EventNinja 1.0.1
dotnet add package EventNinja --version 1.0.1
NuGet\Install-Package EventNinja -Version 1.0.1
<PackageReference Include="EventNinja" Version="1.0.1" />
<PackageVersion Include="EventNinja" Version="1.0.1" />
<PackageReference Include="EventNinja" />
paket add EventNinja --version 1.0.1
#r "nuget: EventNinja, 1.0.1"
#:package EventNinja@1.0.1
#addin nuget:?package=EventNinja&version=1.0.1
#tool nuget:?package=EventNinja&version=1.0.1
โก EventNinja
A powerful, thread-safe logging library for .NET applications with automatic file management and international support.
โจ Features
- ๐ High Performance - Non-blocking, concurrent logging
- ๐ Thread-Safe - Multiple threads can log simultaneously
- ๐ Smart File Organization - Automatic year/month directory structure
- ๐ Auto File Rotation - Configurable file size limits with backup system
- ๐งน Auto Cleanup - Automatic deletion of old log files
- ๐ International Support - Adapts to system culture (Thai Buddhist calendar, English, etc.)
- ๐ฏ Structured Logging - Detailed log entries with timestamp, level, category, and method info
- โ๏ธ Dependency Injection - Full DI container support
- ๐ Multiple Log Levels - Debug, Info, Warning, Error, Critical
- ๐๏ธ Smart Log Level Control - Auto-detects environment with customizable overrides
๐ฆ Installation
# Clone the repository
git clone https://github.com/SolitaryLife/EventNinja.git
# Add project reference
dotnet add reference path/to/EventNinja/EventNinja.csproj
๐ Quick Start
1. Configure Services (Program.cs)
using EventNinja.Extensions;
var builder = Host.CreateDefaultBuilder(args);
builder.ConfigureServices(services =>
{
services.AddEventNinja(config =>
{
config.AppName = "MyApplication";
config.LogDirectory = "Logs";
config.MaxFileSizeMB = 5;
config.DeleteOldLogs = true;
config.RetentionDays = 30;
config.CleanupIntervalHours = 24;
// Log levels auto-detected by environment
// Development: Debug=true, Info=true, Warning=true, Error=true, Critical=true
// Production: Debug=false, Info=false, Warning=true, Error=true, Critical=true
// Optional: Override specific levels if needed
// config.EnableDebug = false; // Custom override
});
});
2. Inject and Use
public class MyService
{
private readonly ILoggerService _logger;
public MyService(ILoggerService logger)
{
_logger = logger;
}
public async Task DoSomething()
{
_logger.LogInfo("Starting operation", "MyService");
try
{
// Your code here
_logger.LogInfo("Operation completed successfully", "MyService");
}
catch (Exception ex)
{
_logger.LogError("Operation failed", ex, "MyService");
throw;
}
}
}
๐ Log Levels
_logger.LogDebug("Debug information");
_logger.LogInfo("General information");
_logger.LogWarning("Warning message");
_logger.LogError("Error occurred", exception);
_logger.LogCritical("Critical system failure", exception);
๐ File Organization
EventNinja automatically organizes log files by year and month according to your system's culture:
English System (en-US)
Logs/
โโโ 2025/
โ โโโ January/
โ โ โโโ MyApp_20250101.log
โ โ โโโ MyApp_20250102.log
โ โ โโโ MyApp_20250102.log1 (backup)
โ โโโ July/
โ โโโ December/
โโโ 2026/
Thai System (th-TH)
Logs/
โโโ 2568/
โ โโโ เธกเธเธฃเธฒเธเธก/
โ โ โโโ MyApp_25680101.log
โ โ โโโ MyApp_25680102.log
โ โโโ เธเธฃเธเธเธฒเธเธก/
โ โโโ เธเธฑเธเธงเธฒเธเธก/
โโโ 2569/
๐ Log Format
[2025-07-05 14:30:25.123] [Info] [MyService] [MyService.DoSomething] Operation completed successfully
[2025-07-05 14:30:26.456] [Warning] [Database] Connection timeout detected
[2025-07-05 14:30:27.789] [Error] [FileService] [FileService.SaveFile] Failed to save file | Exception: System.IO.IOException: Access denied
Format: [Timestamp] [Level] [Category] [Class.Method] Message | Exception
โ๏ธ Configuration Options
Option | Type | Default | Description |
---|---|---|---|
AppName |
string | "Application" | Application name (used in filename) |
LogDirectory |
string | "Logs" | Base directory for log files |
MaxFileSizeMB |
int | 5 | Maximum file size before rotation |
DeleteOldLogs |
bool | false | Enable automatic cleanup |
RetentionDays |
int | 7 | Days to keep log files |
CleanupIntervalHours |
int | 24 | Hours between cleanup runs |
EnableDebug |
bool? | null | Override Debug level (null = auto-detect) |
EnableInfo |
bool? | null | Override Info level (null = auto-detect) |
EnableWarning |
bool? | null | Override Warning level (null = auto-detect) |
EnableError |
bool? | null | Override Error level (null = auto-detect) |
EnableCritical |
bool? | null | Override Critical level (null = auto-detect) |
๐ File Rotation
When a log file reaches the maximum size:
- Current file:
MyApp_20250705.log
โMyApp_20250705.log1
- New current file:
MyApp_20250705.log
(created) - Existing backups:
.log1
โ.log2
,.log2
โ.log3
, etc.
๐งน Auto Cleanup
- Runs every 24 hours (configurable)
- Deletes files older than retention period
- Removes empty directories
- Searches all subdirectories
๐ Thread Safety
EventNinja is designed for high-concurrency scenarios:
- โ Multiple threads can log simultaneously
- โ Non-blocking operations
- โ Background file writing
- โ Thread-safe queue management
๐ฏ Use Cases
- Web Applications - Request logging, error tracking
- Windows Services - Service monitoring, debug info
- Desktop Applications - User activity, system events
- Industrial Applications - PLC communication, sensor data
- Microservices - Distributed logging, performance monitoring
๐ ๏ธ Advanced Usage
Custom Log Categories
_logger.LogInfo("User logged in", "Authentication");
_logger.LogWarning("High memory usage", "Performance");
_logger.LogError("Database connection failed", ex, "Database");
Method Name Auto-Detection
public async Task ProcessOrder(int orderId)
{
// Automatically includes method name "ProcessOrder"
_logger.LogInfo($"Processing order {orderId}", "OrderService");
}
Smart Environment Detection
EventNinja automatically detects your environment and applies appropriate log levels:
Environment Detection Sources:
ASPNETCORE_ENVIRONMENT
environment variableDOTNET_ENVIRONMENT
environment variable- Defaults to "Production" if not found
Default Log Level Presets:
Environment | Debug | Info | Warning | Error | Critical |
---|---|---|---|---|---|
Development | โ | โ | โ | โ | โ |
Production | โ | โ | โ | โ | โ |
// Auto-detection (recommended)
services.AddEventNinja(config =>
{
config.AppName = "MyApp";
// Log levels automatically set based on environment
});
// Custom overrides when needed
services.AddEventNinja(config =>
{
config.AppName = "MyApp";
config.EnableDebug = false; // Force disable debug even in Development
config.EnableInfo = true; // Force enable info even in Production
// Other levels use auto-detection
});
Understanding Custom Override Behavior
Important: Custom overrides always take precedence over environment detection, regardless of whether you're in Development or Production.
Rule:
- Has Custom Value โ Uses your custom setting (ignores environment)
- No Custom Value (null) โ Uses auto-detection based on environment
Example Scenario:
services.AddEventNinja(config =>
{
config.AppName = "MyApp";
config.EnableDebug = false; // Custom Override
config.EnableInfo = true; // Custom Override
// EnableWarning = null (auto-detect)
// EnableError = null (auto-detect)
// EnableCritical = null (auto-detect)
});
Result Table:
Environment | Debug | Info | Warning | Error | Critical |
---|---|---|---|---|---|
Development | โ (custom) | โ (custom) | โ (auto) | โ (auto) | โ (auto) |
Production | โ (custom) | โ (custom) | โ (auto) | โ (auto) | โ (auto) |
Key Points:
EnableDebug = false
applies to both Development and ProductionEnableInfo = true
applies to both Development and Production- Warning, Error, Critical use environment-based defaults
- Custom overrides are environment-independent
When to Use Custom Overrides:
- Disable Debug in Development: When debug logs are too noisy during testing
- Enable Info in Production: When you need specific info logs in production for monitoring
- Temporary Debugging: Enable debug logs in production for troubleshooting (not recommended for long-term)
Best Practice:
// Recommended: Let auto-detection handle most cases
services.AddEventNinja(config =>
{
config.AppName = "MyApp";
// Only override when you have specific requirements
// config.EnableDebug = false; // Uncomment only if needed
});
๐ License
Copyright ยฉ 2025 Tofu Survivors
This project is licensed under the MIT License - see the LICENSE file for details.
Made with โค๏ธ for the .NET community
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
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
v1.0.1: Added package icon. Previous: Initial release with smart environment detection, auto file management, international support, and comprehensive logging features.