Logsmith

Logsmith

Zero-allocation, source-generated structured logging for .NET 10.


Explore the Documentation

Getting Started

Install Logsmith and write your first log method in minutes.

Declaring Log Methods

Attributes, categories, message templates, and EventId generation.

Log Levels

Runtime filtering, per-category overrides, and compile-time level stripping.

Sinks

Six built-in sinks, category filtering, and writing custom sinks.

Formatting & Output

Log formatters, format specifiers, and structured JSON output.

Scoped Context

Enrich log entries with scoped properties using LogScope.Push.

Advanced Features

Sampling, rate limiting, dynamic level switching, and global exception handling.

MEL Bridge

Route ILogger calls through Logsmith sinks with the Extensions.Logging bridge.

Operating Modes

Shared, Standalone, and Abstraction modes for apps and libraries.

Performance

in parameters, custom serialization, caller info, and benchmarks.

Testing

Capture and assert log output with RecordingSink.

Configuration Reference

LogManager API, MSBuild properties, flushing, and shutdown.


Quick Start

// 1. Initialize at startup
LogManager.Initialize(config =>
{
    config.MinimumLevel = LogLevel.Debug;
    config.AddConsoleSink();
    config.AddFileSink("logs/app.log", rollingInterval: RollingInterval.Daily);
});

// 2. Declare log methods
[LogCategory("Renderer")]
public static partial class RenderLog
{
    [LogMessage(LogLevel.Debug, "Draw call {drawCallId} completed in {elapsedMs}ms")]
    public static partial void DrawCallCompleted(int drawCallId, double elapsedMs);

    [LogMessage(LogLevel.Error, "Shader compilation failed: {shaderName}")]
    public static partial void ShaderFailed(string shaderName, Exception ex);
}

// 3. Call them
RenderLog.DrawCallCompleted(42, 1.23);

The generator emits fully specialized, zero-allocation UTF8 code for each log method at compile time. See Getting Started for the full walkthrough.


Why Logsmith?

Zero-Allocation Pipeline

Every log call writes directly to sinks with no heap allocation, no boxing, and no string interpolation. Stackalloc buffers and UTF8 literals throughout.

Source-Generated

A Roslyn source generator emits fully specialized code per log method at compile time. No reflection, no runtime parsing, fully NativeAOT compatible.

Three Operating Modes

Shared (runtime library), Standalone (zero-dependency), or Abstraction (library authors). Pick what fits your deployment.

Structured JSON Output

IStructuredLogSink receives typed properties via Utf8JsonWriter. No runtime serialization overhead — the generator writes each field directly.

Compile-Time Level Stripping

[Conditional] attributes remove log calls below a configured threshold at compile time. Stripped levels have zero cost — the calls don't exist in the binary.

MEL Bridge

Logsmith.Extensions.Logging routes ILogger calls through Logsmith sinks. Drop-in integration for existing dependency injection setups.