Deneblab.ZLoggerExtensions
0.1.11
See the version list below for details.
dotnet add package Deneblab.ZLoggerExtensions --version 0.1.11
NuGet\Install-Package Deneblab.ZLoggerExtensions -Version 0.1.11
<PackageReference Include="Deneblab.ZLoggerExtensions" Version="0.1.11" />
<PackageVersion Include="Deneblab.ZLoggerExtensions" Version="0.1.11" />
<PackageReference Include="Deneblab.ZLoggerExtensions" />
paket add Deneblab.ZLoggerExtensions --version 0.1.11
#r "nuget: Deneblab.ZLoggerExtensions, 0.1.11"
#:package Deneblab.ZLoggerExtensions@0.1.11
#addin nuget:?package=Deneblab.ZLoggerExtensions&version=0.1.11
#tool nuget:?package=Deneblab.ZLoggerExtensions&version=0.1.11
ZLogger Extensions
Extensions and advanced features for ZLogger, including advanced file logging with archiving, rotation, and enhanced console logging capabilities.
Features
- 🚀 Advanced File Logger: High-performance file logging with size-based rolling, automatic archiving, and retention policies
- 🎨 Console Logger with Colors: Enhanced console logging with color support for different log levels
- 📦 Easy Integration: Seamless integration with .NET's logging infrastructure via
ILoggingBuilder - ⚙️ Flexible Configuration: Support for both code-based and
appsettings.jsonconfiguration - 🔒 Thread-Safe: All components are thread-safe for multi-threaded applications
- 🔧 External Process Support: Allow reading/deleting log files during active logging
Installation
Install the package via NuGet Package Manager:
dotnet add package Deneblab.ZLoggerExtensions
Or via Package Manager Console:
Install-Package Deneblab.ZLoggerExtensions
Quick Start
Advanced File Logger
using Microsoft.Extensions.Logging;
using ZLoggerExtensions.AdvanceFileLogger;
var services = new ServiceCollection();
services.AddLogging(builder =>
{
builder.AddAdvanceFileLogger("logs/app.log");
});
var serviceProvider = services.BuildServiceProvider();
var logger = serviceProvider.GetRequiredService<ILogger<Program>>();
logger.LogInformation("Application started");
logger.LogWarning("This is a warning");
logger.LogError("This is an error");
Advanced Configuration
services.AddLogging(builder =>
{
builder.AddAdvanceFileLogger(options =>
{
options.FilePath = "logs/myapp.log";
options.MaxBytes = 100 * 1024 * 1024; // 100MB
options.MaxArchivedFiles = 10;
options.ArchiveDirectory = "archive";
options.AllowExternalAccess = true;
options.AutoFlush = true;
});
});
Configuration via appsettings.json
{
"Logging": {
"AdvanceFile": {
"FilePath": "logs/app.log",
"MaxBytes": 52428800,
"MaxArchivedFiles": 7,
"ArchiveDirectory": "archive",
"AllowExternalAccess": true,
"AutoFlush": true
}
}
}
Advanced File Logger
The Advanced File Logger provides enterprise-grade file logging capabilities with the following features:
Key Features
- Size-based Rolling: Configurable file size limit (default: 50MB)
- Automatic Archiving: Move rolled files to archive subdirectory
- Retention Policy: Configurable number of archived files to keep (default: 7)
- External Process Support: Allow reading/deleting log files during logging
- ZLogger Integration: Full compatibility with ZLogger architecture
Configuration Options
| Property | Type | Default | Description |
|---|---|---|---|
FilePath |
string | "logs/app.log" | Base file path for log files |
MaxBytes |
long | 50MB | File size limit for rolling (0 disables) |
MaxArchivedFiles |
int | 7 | Maximum archived files to retain |
ArchiveDirectory |
string | "archive" | Archive directory name |
AllowExternalAccess |
bool | true | Allow external process file access |
AutoFlush |
bool | true | Flush after each write |
CreateDirectories |
bool | true | Create directories if missing |
Encoding |
Encoding | UTF8 | File encoding |
BufferSize |
int | 4096 | File buffer size |
File Naming Convention
The AdvanceFileLogger follows ZLogger's rolling file naming convention:
- Current file:
app.log - Rolled files:
app_20231225_143045.log - Archived files:
archive/app_20231225_143045.log
Console Logger with Colors
Enhanced console logging with color support for different log levels, providing better visual distinction in console applications.
Architecture
The library consists of several well-designed components:
Advanced File Logger Components
- AdvanceFileLoggerProvider: Main provider implementing
ILoggerProvider - AdvanceFileWriter: Core file writing with rolling logic
- FileNameProvider: Handles ZLogger-style file naming
- FileArchiver: Manages archiving and retention policy
- AdvanceFileLoggerOptions: Configuration class
Requirements
- .NET 8.0 or later
- ZLogger 2.5.10 or later
Dependencies
- ZLogger: High-performance structured logging library
- Microsoft.Extensions.Logging: .NET logging abstractions
- Microsoft.Extensions.DependencyInjection: Dependency injection framework
Performance
The library is designed for high performance:
- Configurable buffer size for optimal I/O performance
- Optional auto-flush for immediate persistence
- Efficient file size monitoring
- Minimal memory allocation during logging
- Thread-safe operations without blocking
Error Handling
The logger is designed to be resilient:
- Failed writes attempt recovery by reopening files
- Archive failures don't stop logging
- Invalid configurations are validated at startup
- Graceful degradation when external processes interfere
Testing
The library includes comprehensive test coverage:
# Run all tests
dotnet test
# Run tests with coverage
dotnet test --collect:"XPlat Code Coverage"
Test coverage includes:
- Basic logging functionality
- File rolling behavior
- Archive retention policy
- Configuration validation
- Provider integration
- External file access scenarios
- Thread safety verification
Contributing
We welcome contributions! Please see our contributing guidelines for details on how to:
- Report bugs
- Suggest enhancements
- Submit pull requests
- Follow coding standards
License
This project is licensed under the MIT License - see the LICENSE file for details.
Acknowledgments
- ZLogger - The foundational logging library this extends
- Microsoft.Extensions.Logging - .NET logging infrastructure
Support
- 📖 Documentation
- 🐛 Issues
- 💬 Discussions
Made with ❤️ by DenebLab
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | 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. |
-
net8.0
- Microsoft.Extensions.DependencyInjection (>= 8.0.0)
- Microsoft.Extensions.Logging (>= 8.0.0)
- Microsoft.Extensions.Logging.Configuration (>= 8.0.0)
- Microsoft.Extensions.Options (>= 8.0.2)
- ZLogger (>= 2.5.10)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.