SkyWebFramework.Logging
1.0.1
dotnet add package SkyWebFramework.Logging --version 1.0.1
NuGet\Install-Package SkyWebFramework.Logging -Version 1.0.1
<PackageReference Include="SkyWebFramework.Logging" Version="1.0.1" />
<PackageVersion Include="SkyWebFramework.Logging" Version="1.0.1" />
<PackageReference Include="SkyWebFramework.Logging" />
paket add SkyWebFramework.Logging --version 1.0.1
#r "nuget: SkyWebFramework.Logging, 1.0.1"
#:package SkyWebFramework.Logging@1.0.1
#addin nuget:?package=SkyWebFramework.Logging&version=1.0.1
#tool nuget:?package=SkyWebFramework.Logging&version=1.0.1
🪵 SkyWebFramework.Logging
<div align="center">
A lightweight, high-performance file logger for .NET
Smart category filtering • Automatic compression • Zero-config simplicity
</div>
✨ Why SkywebFramework.Logging?
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();
🎯 Key Features
<table> <tr> <td width="50%">
📁 Smart File Management
- Automatic log rotation
- Configurable size limits
- Timestamp-based file naming
- Keep N most recent logs
</td> <td width="50%">
🗜️ Intelligent Compression
- GZip compression (85%+ size reduction)
- Automatic processing of old logs
- Asynchronous, non-blocking
- Configurable compression levels
</td> </tr> <tr> <td width="50%">
🎯 Category Filtering
- Per-namespace log levels
- Wildcard pattern matching
- Reduce third-party noise
- Debug specific components
</td> <td width="50%">
⚡ High Performance
- Background Channel-based processing
- Non-blocking writes
- Minimal memory footprint
- Production-ready throughput
</td> </tr> </table>
📦 Installation
dotnet add package SkywebFramework.Logging
🚀 Quick Start
Basic Console App
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!");
ASP.NET Core
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();
⚙️ Configuration
Basic Options
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
});
🎨 Smart Category Filtering
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;
});
🗜️ Compression Settings
builder.AddEasyFileLogging(options =>
{
options.CompressOldLogs = true;
options.CompressionLevel = CompressionLevel.Optimal;
// Result: 10MB log → ~1.5MB compressed (85% savings!)
});
📝 Usage Examples
In Your Services
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;
}
}
}
Structured Logging
_logger.LogInformation(
"Order processed: {OrderId} | User: {UserId} | Total: {Amount:C} | Items: {ItemCount}",
order.Id, user.Id, order.Total, order.Items.Count
);
🎯 Configuration Patterns
🛠️ Development Environment
options.MinLevel = LogLevel.Debug;
options.CategoryLevels["MyApp.*"] = LogLevel.Trace;
options.CategoryLevels["Microsoft.*"] = LogLevel.Information;
🚀 Production Environment
options.MinLevel = LogLevel.Warning;
options.CategoryLevels["MyApp.Services.*"] = LogLevel.Information;
options.CategoryLevels["MyApp.Data.*"] = LogLevel.Warning;
options.CategoryLevels["Microsoft.*"] = LogLevel.Error;
options.CompressOldLogs = true;
🐛 Troubleshooting Mode
// Temporarily enable detailed logging for investigation
options.CategoryLevels["MyApp.Services.PaymentService"] = LogLevel.Trace;
options.CategoryLevels["MyApp.Data.PaymentRepository"] = LogLevel.Debug;
📊 Output Formats
Compact Text (Default)
[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)
Detailed Text
------------------------------------------------------------------------------------------
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
------------------------------------------------------------------------------------------
JSON Format
{
"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
}
🔧 File Management
Log Rotation Behavior
| 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 |
Compression Benefits
- 10MB log file → ~1.5MB compressed (85% reduction)
- Keep more history without extra disk space
- Faster backups and transfers
- Asynchronous processing (no performance impact)
💡 Performance Tips
✅ 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)
🔍 Troubleshooting
Logs Not Appearing?
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
File Permission Issues?
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
📋 Complete Production Example
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;
});
🤝 Contributing
We welcome contributions! Found a bug or have a feature idea?
📄 License
MIT License - Free for commercial and personal use.
<div align="center">
Made with ❤️ by the SkywebFramework team
Documentation • NuGet • GitHub
</div>
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 is compatible. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net6.0
- Microsoft.Extensions.Logging (>= 6.0.0)
- Microsoft.Extensions.Logging.Configuration (>= 6.0.0)
-
net7.0
- Microsoft.Extensions.Logging (>= 7.0.0)
- Microsoft.Extensions.Logging.Configuration (>= 7.0.0)
-
net8.0
- Microsoft.Extensions.Logging (>= 8.0.0)
- Microsoft.Extensions.Logging.Configuration (>= 8.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version 1.0.0 - Initial Release
✨ Features:
- High-performance async file logging with minimal overhead
- Smart category-based filtering (include/exclude patterns)
- Automatic daily log rotation with customizable naming
- Background file compression (gzip) for older logs
- Configurable retention policies (days/file count)
- Thread-safe non-blocking writes
- Structured logging support with scopes
- Zero external dependencies (except Microsoft.Extensions.Logging)
- Production-ready with extensive error handling
- Supports .NET 6.0, 7.0, and 8.0
🚀 Performance:
- Async non-blocking I/O operations
- Efficient buffering and batching
- Background compression doesn't block logging
- Minimal memory allocation
📦 Easy Integration:
- Simple setup with ILoggingBuilder extension
- Fluent configuration API
- Works with ASP.NET Core, Console Apps, and Worker Services
- Compatible with standard ILogger interface