Easy.Logging is a lightweight, high-performance caching library for .NET that supports MemoryLogging, Redis, and multi-layer caching with pluggable serialization.
$ dotnet add package Easy.LoggingEasy.Logging is a high-performance, thread-safe, and asynchronous logging library for .NET applications.
It is designed to handle high-throughput scenarios by leveraging System.Threading.Channels for background processing (Fire-and-Forget), ensuring your application's main thread is never blocked by I/O operations.
BufferedSink to offload logging to a background thread, preventing I/O bottlenecks.Properties) for advanced querying in log management systems.Install via NuGet Package Manager:
Install-Package Easy.Logging
Or via .NET CLI:
dotnet add package Easy.Logging
Register the core services and the specific sinks you need. The library automatically wraps heavy sinks (like File/Redis) in a BufferedSink for performance.
using Easy.Logging.Extensions;
var builder = WebApplication.CreateBuilder(args);
// 1. Add Easy Logging Core
builder.Services.AddEasyLogging();
// 2. Add Sinks (Destinations)
builder.Services.AddConsoleLogger(); // Colored Console
builder.Services.AddRollingFileLogger("Logs"); // Daily rolling files (e.g., log-2023-10-01.txt)
builder.Services.AddRedisLogger("localhost:6379", "app-logs"); // Pushes to a Redis List
// builder.Services.AddDatabaseLogger<AppDbContext>(); // Writes to SQL DB via EF Core
var app = builder.Build();
Inject the Easy.Logging.Core.ILogger interface (not Microsoft's ILogger) into your classes.
using Easy.Logging.Core;
using Microsoft.AspNetCore.Mvc;
public class OrderController : ControllerBase
{
private readonly ILogger _logger;
public OrderController(ILogger logger)
{
_logger = logger;
}
[HttpPost]
public async Task<IActionResult> CreateOrder(OrderDto order)
{
// 1. Simple Info Log
await _logger.InfoAsync("Processing new order...", context: "OrderController");
try
{
// Business Logic...
throw new Exception("Payment gateway timeout.");
}
catch (Exception ex)
{
// 2. Error Log with Exception
await _logger.ErrorAsync("Failed to process order.", exception: ex.ToString());
}
// 3. Structured Log (Best for searching/filtering)
await _logger.LogAsync(new LogEntry
{
Level = LogLevel.Warn,
Message = "High value transaction detected",
Properties = new Dictionary<string, object>
{
{ "OrderId", order.Id },
{ "Amount", order.Amount },
{ "Currency", "USD" }
}
});
return Ok();
}
}
The library follows a modular Logger vs. Sink architecture:
| Component | Description |
|---|---|
| ILogger (CompositeLogger) | The "Manager". It receives log entries from your code and broadcasts them to all registered sinks. |
| ILogSink (The Workers) | The actual destinations where logs are written (e.g., ConsoleSink, FileSink, RedisSink). |
| BufferedSink (The Buffer) | A decorator that wraps slow sinks (File/DB). It holds logs in a memory queue (Channel<T>) and writes them in the background, ensuring your app stays fast. |
| ILogFormatter | Converts the LogEntry object into a string format (Default is JSON). |
To use the Database Sink, your DbContext must implement the ILogDbContext interface.
Implement Interface in DbContext:
public class AppDbContext : DbContext, ILogDbContext
{
public DbSet<LogRecord> Logs { get; set; } // The table for logs
}
Register in Program.cs:
builder.Services.AddDatabaseLogger<AppDbContext>();
Contributions and suggestions are welcome. Please open an issue or submit a pull request.
For questions, contact us via elmin.alirzayev@gmail.com or GitHub.
This project is licensed under the MIT License.
© 2025 Elmin Alirzayev / Easy Code Tools