InsightLog 1.0.1

dotnet add package InsightLog --version 1.0.1
                    
NuGet\Install-Package InsightLog -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="InsightLog" Version="1.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="InsightLog" Version="1.0.1" />
                    
Directory.Packages.props
<PackageReference Include="InsightLog" />
                    
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 InsightLog --version 1.0.1
                    
#r "nuget: InsightLog, 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 InsightLog@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=InsightLog&version=1.0.1
                    
Install as a Cake Addin
#tool nuget:?package=InsightLog&version=1.0.1
                    
Install as a Cake Tool

🔧 InsightLog

Build Status NuGet License: MIT .NET 8

A high-performance, context-aware logging library for .NET 8+ with automatic context capture, timing scopes, and structured output support.

âœĻ Features

  • ðŸŽŊ Auto Context Capture: Automatically captures file, member, line number, thread/task IDs
  • ⏱ïļ Timing Scopes: Built-in performance measurement with using pattern
  • 🔗 Correlation IDs: Automatic correlation tracking via Activity.Current or generated IDs
  • ðŸŽĻ Colorized Console: Beautiful, readable console output with customizable themes
  • 📊 Structured Logging: Native JSON output for ELK Stack, Seq, and other systems
  • 🔒 Parameter Redaction: Automatic sensitive data redaction by name or regex
  • 📈 Async-Safe Indentation: Per-logical-call indentation using AsyncLocal
  • 🎛ïļ Flexible Sinks: Console, rolling file, and JSON sinks included
  • ⚡ High Performance: Sub-microsecond no-op calls, minimal allocations
  • 💉 DI Ready: First-class dependency injection support

ðŸ“Ķ Installation

# Core library
dotnet add package InsightLog

# Sinks (optional)
dotnet add package InsightLog.Console
dotnet add package InsightLog.File
dotnet add package InsightLog.Json

🚀 90-Second Quickstart

using InsightLog;
using InsightLog.Console;

// Create a logger
var logger = InsightLogger.Create(options =>
{
    options.MinimumLevel = LogLevel.Info;
    options.UseColors = true;
    options.SlowThresholdMs = 500;
    options.Redact("password", "apiKey");
    options.Sinks.Add(new ConsoleSink(options));
});

// Log messages
logger.Info("Application started");
logger.Warn("Memory usage at {Percentage}%", 85);

// Use scopes for grouped operations
using (logger.Scope("DatabaseOperation"))
{
    logger.Debug("Connecting to database");
    // ... do stuff ...
    logger.Info("Query completed with {RowCount} rows", 42);
}

// Measure performance
using (logger.Measure("DataProcessing"))
{
    // ... expensive operation ...
}

// Handle exceptions
try
{
    // ... risky operation ...
}
catch (Exception ex)
{
    logger.Error(ex, "Operation failed for user {UserId}", userId);
}

ðŸŽŊ Feature Examples

Dependency Injection

// In Program.cs or Startup.cs
builder.Services.AddInsightLog(options =>
{
    options.MinimumLevel = LogLevel.Debug;
    options.SlowThresholdMs = 1000;
    options.Sinks.Add(new ConsoleSink(options));
    options.Sinks.Add(new FileSink("logs/app-.log", options));
});

// In your service
public class MyService
{
    private readonly ILogger _logger;
    
    public MyService(ILogger logger)
    {
        _logger = logger;
    }
    
    public async Task ProcessAsync()
    {
        using (_logger.Scope("ProcessAsync"))
        {
            _logger.Info("Starting process");
            // ... do work ...
        }
    }
}

Parameter Redaction

var logger = InsightLogger.Create(options =>
{
    // Redact by exact name (case-insensitive)
    options.Redact("password", "creditCard", "ssn");
    
    // Redact by regex pattern
    options.Redact(@"\b\d{3}-\d{2}-\d{4}\b"); // SSN pattern
    
    options.Sinks.Add(new ConsoleSink(options));
});

// These sensitive values will be automatically redacted
logger.Info("User login: {Username} with {Password}", "john", "secret123");
// Output: User login: john with ***REDACTED***

Structured JSON Output

var logger = InsightLogger.Create(options =>
{
    options.OutputFormat = OutputFormat.Json;
    options.Sinks.Add(new JsonSink("logs/structured-.json"));
});

logger.Info("Order processed", new { OrderId = "12345", Amount = 99.99 });
// Output: {"timestamp":"2025-01-15T10:30:45Z","level":"Info","message":"Order processed",...}

Performance Monitoring

var logger = InsightLogger.Create(options =>
{
    options.SlowThresholdMs = 200; // Mark operations > 200ms as slow
    options.Sinks.Add(new ConsoleSink(options));
});

using (logger.Measure("SlowOperation"))
{
    await Task.Delay(300); // Simulated work
}
// Output includes: ⚠ SLOW OPERATION - completed in 301.23ms

📊 Feature Matrix

Feature InsightLog Serilog NLog log4net
Auto Context Capture ✅ ⚠ïļ âš ïļ âŒ
Built-in Timing ✅ ❌ ❌ ❌
AsyncLocal Scopes ✅ ✅ ✅ ⚠ïļ
Zero-Dep Core ✅ ❌ ❌ ❌
Native Redaction ✅ ⚠ïļ âš ïļ âŒ
Sub-Ξs No-op ✅ ✅ ✅ ⚠ïļ
DI Integration ✅ ✅ ✅ ✅

⚡ Performance

Benchmark results on .NET 8.0 (Intel Core i7-10700K):

Operation Mean Time Allocated
No-op (filtered) 0.9 ns 0 B
Simple Log 8.3 ns 0 B
Complex Log (4 props) 42.1 ns 192 B
With Redaction 51.2 ns 256 B
Scope Creation 23.4 ns 88 B

🔧 Configuration

var logger = InsightLogger.Create(options =>
{
    // Logging levels
    options.MinimumLevel = LogLevel.Debug;
    
    // Output format
    options.OutputFormat = OutputFormat.Text; // or Json
    options.UseColors = true;
    
    // Performance
    options.SlowThresholdMs = 1000;
    options.SampleRate = 1; // 1 = log all, 2 = log 50%, etc.
    options.MaxMessageLength = 4000;
    
    // Context
    options.IncludeScopes = true;
    options.IncludeCallerInfo = true;
    
    // Redaction
    options.Redact("password", "token", @"\b\d{16}\b");
    
    // Sinks
    options.Sinks.Add(new ConsoleSink(options));
    options.Sinks.Add(new FileSink("logs/app-.log", options));
    options.Sinks.Add(new JsonSink("logs/structured-.json"));
});

📁 Output Examples

Console Output (Text)

[10:30:45.123] [INF] [corr:abc12345] [Main()@Program.cs:42] Application started
  â†ģ props: { Version=1.0.0, Environment=Production }
[10:30:45.234] [WRN] [corr:abc12345] [CheckHealth()@Service.cs:18] High memory usage
  ⚠ SLOW OPERATION
[10:30:45.345] [ERR] [corr:abc12345] [Process()@Worker.cs:67] Operation failed
  Exception: System.InvalidOperationException
  Connection timeout
    at Worker.Process() in Worker.cs:line 67

JSON Output

{
  "timestamp": "2025-01-15T10:30:45.123Z",
  "level": "Info",
  "message": "Application started",
  "correlationId": "abc12345",
  "threadId": 1,
  "caller": {
    "member": "Main",
    "file": "Program.cs",
    "line": 42
  },
  "properties": {
    "Version": "1.0.0",
    "Environment": "Production"
  }
}

ðŸ›Ģïļ Roadmap

  • Cloud provider sinks (AWS CloudWatch, Azure Monitor, GCP)
  • OpenTelemetry integration
  • Metrics collection
  • Configuration from appsettings.json
  • Log aggregation and buffering
  • Dynamic log level changes

ðŸĪ Contributing

We welcome contributions! Please see CONTRIBUTING.md for details.

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.

🙏 Acknowledgments

  • Inspired by the best features of Serilog, NLog, and ASP.NET Core logging
  • Built with performance patterns from BenchmarkDotNet insights
  • Community feedback and contributions

Built 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 (3)

Showing the top 3 NuGet packages that depend on InsightLog:

Package Downloads
InsightLog.Json

Structured JSON sink for InsightLog optimized for ELK and Seq integration.

InsightLog.File

Rolling file sink for InsightLog with date-based rotation and size limits.

InsightLog.Console

Console sink for InsightLog with colorized output and theme support.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.1 186 11/8/2025