EventNinja 1.0.1

dotnet add package EventNinja --version 1.0.1
                    
NuGet\Install-Package EventNinja -Version 1.0.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="EventNinja" Version="1.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="EventNinja" Version="1.0.1" />
                    
Directory.Packages.props
<PackageReference Include="EventNinja" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add EventNinja --version 1.0.1
                    
#r "nuget: EventNinja, 1.0.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package EventNinja@1.0.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=EventNinja&version=1.0.1
                    
Install as a Cake Addin
#tool nuget:?package=EventNinja&version=1.0.1
                    
Install as a Cake Tool

โšก EventNinja

A powerful, thread-safe logging library for .NET applications with automatic file management and international support.

.NET License Thread-Safe Production Ready

โœจ 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:

  1. Current file: MyApp_20250705.log โ†’ MyApp_20250705.log1
  2. New current file: MyApp_20250705.log (created)
  3. 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:

  1. ASPNETCORE_ENVIRONMENT environment variable
  2. DOTNET_ENVIRONMENT environment variable
  3. 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:

  1. EnableDebug = false applies to both Development and Production
  2. EnableInfo = true applies to both Development and Production
  3. Warning, Error, Critical use environment-based defaults
  4. 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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.1 114 9/5/2025
1.0.0 119 9/5/2025

v1.0.1: Added package icon. Previous: Initial release with smart environment detection, auto file management, international support, and comprehensive logging features.