SkyWebFramework.Logging provides enterprise-grade file logging capabilities with zero external dependencies (except Microsoft.Extensions.Logging). Features include smart category-based filtering, automatic daily log rotation, background file compression, configurable retention policies, async non-blocking writes, structured logging support, and production-ready performance optimizations. Ideal for microservices, web APIs, and distributed systems.
$ dotnet add package SkyWebFramework.LoggingA lightweight, high-performance file logger for .NET
Smart category filtering • Automatic compression • Zero-config simplicity
Perfect for applications that need flexible, disk-efficient logging without the complexity of larger frameworks. Get production-ready logging in seconds, not hours.
// It's really this easy
builder.Logging.AddEasyFileLogging();
📁 Smart File Management
|
🗜️ Intelligent Compression
|
🎯 Category Filtering
|
⚡ High Performance
|
dotnet add package SkywebFramework.Logging
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
var services = new ServiceCollection();
services.AddLogging(builder => builder.AddEasyFileLogging());
var logger = services.BuildServiceProvider()
.GetRequiredService<ILogger<Program>>();
logger.LogInformation("🎉 Hello from SkywebFramework.Logging!");
var builder = WebApplication.CreateBuilder(args);
builder.Logging.AddEasyFileLogging(options =>
{
options.Path = "logs/webapi.log";
options.MinLevel = LogLevel.Information;
options.CompressOldLogs = true;
});
var app = builder.Build();
builder.AddEasyFileLogging(options =>
{
options.Path = "logs/myapp.log"; // Log file location
options.MaxFileSizeBytes = 10 * 1024 * 1024; // 10 MB rotation threshold
options.MinLevel = LogLevel.Warning; // Global minimum level
options.KeepFiles = 10; // Retain 10 old files
options.UseJsonFormat = false; // Text format (default)
options.UseCompactFormat = true; // Compact text output
});
Set different log levels for different parts of your application:
builder.AddEasyFileLogging(options =>
{
options.MinLevel = LogLevel.Warning; // Default for everything
// 🔍 Detailed logging for your code
options.CategoryLevels["MyApp.Services"] = LogLevel.Debug;
options.CategoryLevels["MyApp.Data"] = LogLevel.Information;
// 🔇 Reduce framework noise
options.CategoryLevels["Microsoft.AspNetCore"] = LogLevel.Error;
options.CategoryLevels["Microsoft.EntityFrameworkCore"] = LogLevel.Warning;
// 🐛 Deep dive into specific issues
options.CategoryLevels["MyApp.Services.PaymentService"] = LogLevel.Trace;
});
builder.AddEasyFileLogging(options =>
{
options.CompressOldLogs = true;
options.CompressionLevel = CompressionLevel.Optimal;
// Result: 10MB log → ~1.5MB compressed (85% savings!)
});
public class UserService
{
private readonly ILogger<UserService> _logger;
public UserService(ILogger<UserService> logger)
{
_logger = logger;
}
public async Task<User> CreateUserAsync(string username)
{
_logger.LogDebug("Creating user: {Username}", username);
try
{
var user = await _repository.CreateAsync(username);
_logger.LogInformation("✓ User created: {Username} (ID: {UserId})",
username, user.Id);
return user;
}
catch (Exception ex)
{
_logger.LogError(ex, "✗ Failed to create user: {Username}", username);
throw;
}
}
}
_logger.LogInformation(
"Order processed: {OrderId} | User: {UserId} | Total: {Amount:C} | Items: {ItemCount}",
order.Id, user.Id, order.Total, order.Items.Count
);
options.MinLevel = LogLevel.Debug;
options.CategoryLevels["MyApp.*"] = LogLevel.Trace;
options.CategoryLevels["Microsoft.*"] = LogLevel.Information;
options.MinLevel = LogLevel.Warning;
options.CategoryLevels["MyApp.Services.*"] = LogLevel.Information;
options.CategoryLevels["MyApp.Data.*"] = LogLevel.Warning;
options.CategoryLevels["Microsoft.*"] = LogLevel.Error;
options.CompressOldLogs = true;
// Temporarily enable detailed logging for investigation
options.CategoryLevels["MyApp.Services.PaymentService"] = LogLevel.Trace;
options.CategoryLevels["MyApp.Data.PaymentRepository"] = LogLevel.Debug;
[2024-01-15 14:30:45.123] [Information] [MyApp.Services.UserService] User created successfully
[2024-01-15 14:30:45.456] [Warning] [MyApp.Data.UserRepository] Slow query detected (342ms)
------------------------------------------------------------------------------------------
Time: 2024-01-15 14:30:45.123
Level: Information
Category: MyApp.Services.UserService
Machine: PROD-SERVER-01
Thread ID: 7
Message: User created successfully
------------------------------------------------------------------------------------------
{
"Timestamp": "2024-01-15T14:30:45.123Z",
"Level": "Information",
"Category": "MyApp.Services.UserService",
"Message": "User created successfully",
"Exception": null,
"Machine": "PROD-SERVER-01",
"ThreadId": 7
}
| Event | Action |
|---|---|
File reaches MaxFileSizeBytes | Current log rotated to myapp.log.20240115_143045 |
| Compression enabled | Rotated file compressed to myapp.log.20240115_143045.gz |
Exceeds KeepFiles limit | Oldest files automatically deleted |
✅ Use appropriate log levels in production
✅ Enable category filtering to reduce noise
✅ Enable compression for long-term storage
✅ Set reasonable file size limits (10-50MB recommended)
❌ Don't log everything at Trace level in production
❌ Don't set MaxFileSizeBytes too small (causes frequent rotations)
Check your filtering configuration:
// ❌ This might be filtered
_logger.LogDebug("Debug message"); // Won't appear if MinLevel = Information
// ✅ This will appear
_logger.LogInformation("Info message"); // Appears if MinLevel <= Information
Ensure your application has write access to the log directory:
# Linux/Mac
chmod 755 /path/to/logs
# Windows: Grant write permissions to the application user
builder.Logging.AddEasyFileLogging(options =>
{
// File management
options.Path = "logs/production.log";
options.MaxFileSizeBytes = 50 * 1024 * 1024; // 50 MB
options.KeepFiles = 30; // 30 days of logs
// Output format
options.UseJsonFormat = true; // Structured logs
// Smart filtering
options.MinLevel = LogLevel.Warning;
options.CategoryLevels["MyApp.Services"] = LogLevel.Information;
options.CategoryLevels["MyApp.Data"] = LogLevel.Debug;
options.CategoryLevels["Microsoft.*"] = LogLevel.Error;
options.CategoryLevels["System.Net.Http.*"] = LogLevel.Warning;
// Compression
options.CompressOldLogs = true;
options.CompressionLevel = CompressionLevel.Optimal;
});
We welcome contributions! Found a bug or have a feature idea?
MIT License - Free for commercial and personal use.
Made with ❤️ by the SkywebFramework team
Documentation • NuGet • GitHub