Skip to content

Repository files navigation

Logsmith CI

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

Logsmith is a logging framework where the source generator is the framework. Every log method is analyzed at compile time, and the generator emits fully specialized, zero-allocation UTF8 code tailored to your exact parameters. No reflection. No boxing. No runtime parsing of message templates.

Documentation | API Reference


Packages

NameNuGetDescription
LogsmithLogsmithRuntime library with public types, sinks, and the bundled source generator. Default mode: Shared.
Logsmith.GeneratorLogsmith.GeneratorThin meta-package. Depends on Logsmith for the generator and build assets only — no runtime DLL. Default mode: Standalone.
Logsmith.Extensions.LoggingLogsmith.Extensions.LoggingMicrosoft.Extensions.Logging bridge. Routes ILogger calls through Logsmith sinks.

Why Logsmith

Most .NET logging frameworks parse message templates at runtime, box value-type arguments into object[], and dispatch through multiple abstraction layers before bytes reach an output target. For applications where logging sits on the hot path — game engines, trading systems, NativeAOT deployments — those costs are measurable.

Logsmith takes the source-generator approach to its conclusion: the generator does not supplement a runtime framework, it replaces it entirely. It reads your method declarations at build time, knows the concrete types of every parameter, and emits direct UTF8 formatting calls with pre-computed property names and type-specific serialization paths.


Comparison with Other Frameworks

CapabilityLogsmithMEL + LoggerMessageZLoggerSerilogNLog
Source-generated method bodiesYesYesYesNoNo
Zero runtime dependency modeYes (standalone)No (requires MEL)No (requires MEL)NoNo
Abstraction mode for librariesYesNoNoNoNo
Zero allocation hot pathYesPartial (MEL infra allocates)YesNoNo
UTF8 end-to-endYesNo (UTF16 strings)YesNoNo
Structured loggingYes (Utf8JsonWriter)YesYesYesYes
Compile-time level strippingYes ([Conditional])NoNoNoNo
No boxing of value typesYesYes (generated path)YesNo (object[] params)No (object[] params)
No reflectionYesYesPartialNo (used in enrichers)No (used in layouts)
NativeAOT compatibleYesYesYesPartialPartial
Compile-time diagnosticsYes (LSMITH001-010)YesLimitedNoNo
Log sampling / rate limitingYes (compile-time)NoNoNoNo
Scoped context (AsyncLocal)Yes (LogScope)Yes (ILogger.BeginScope)YesYes (LogContext)Yes (ScopeContext)
Dynamic level switchingYes (env var, file)Yes (IOptionsMonitor)YesYes (LoggingLevelSwitch)Yes (config reload)
Custom type serializationILogStructurableILogger.BeginScopeIZLoggerFormattableDestructure policiesCustom layout renderers
MEL ecosystem compatibilityYes (bridge package)NativeNativeVia Serilog.Extensions.LoggingVia NLog.Extensions.Logging
DI container requiredNoTypically yesTypically yesNoNo
Transitive dependenciesZero (standalone)MEL abstractionsMEL + ZLoggerSerilog + sinksNLog

Features


Quick Start

// 1. Initialize at startupLogManager.Initialize(config =>{config.MinimumLevel=LogLevel.Debug;config.AddConsoleSink();config.AddFileSink("logs/app.log",rollingInterval:RollingInterval.Daily);});// 2. Declare log methods[LogCategory("Renderer")]publicstaticpartialclassRenderLog{[LogMessage(LogLevel.Debug,"Draw call {drawCallId} completed in {elapsedMs}ms")]publicstaticpartialvoidDrawCallCompleted(intdrawCallId,doubleelapsedMs);[LogMessage(LogLevel.Error,"Shader compilation failed: {shaderName}")]publicstaticpartialvoidShaderFailed(stringshaderName,Exceptionex);}// 3. Call themRenderLog.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.


Benchmarks

Full benchmark results comparing Logsmith against MEL, Serilog, NLog, and ZLogger are available in docs/benchmarks.md.


License

This project is licensed under the MIT License.

About

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

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages