serilog
Structured logging with Serilog for .NET 10 applications. Covers two-stage bootstrap, appsettings configuration, enrichers, sinks, request logging, destructuring, and Serilog.Expressions. Load this skill when setting up Serilog, configuring log sinks, enrichers, or structured logging, or when the us
By codewithmukesh · 1,204 installs
npx skills add codewithmukesh/dotnet-claude-kit --skill serilog
Source repository · Upstream listing
Serilog
Core Principles
1. Two stage initialization — Create a bootstrap logger for startup, then replace it with the full logger after DI is ready. This captures startup errors that would otherwise be lost.
2. AddSerilog() over UseSerilog() — Use builder.Services.AddSerilog() (the modern API) instead of builder.Host.UseSerilog() . It integrates with DI services via ReadFrom.Services(services) .
3. Message templates, not interpolation — {PropertyName} syntax creates structured data that can be queried. String interpolation ( $"..." ) breaks structure and allocates even when the log level is disabled.
4. Configure via appsettings.json — Keep log levels, sinks, and overrides in configuration so they can change per environment without redeployment.
Patterns
Two Stage Bootstrap Setup
appsettings.json Configuration
Override section uses namespace prefixes matched against SourceContext . More specific prefixes take precedence.
Request Logging Middleware
Replaces the multiple per request log events from ASP.NET Core with a single summary event.
Structured Logging and Destructuring
Scoped Properties with LogContext
Requires .Enrich.FromLogContext() on the logger configuration.
OpenTelemetry Sink (OTLP Export)
Export Serilog events directly to any OTLP backend without the OpenTelemetry SDK:
Serilog.Expressions for Filtering
Requires the Serilog.Expressions package.
[LoggerMessage] Source Generator for Hot Paths
Built into Microsoft.Extensions.Logging.Abstractions — compile time generated, zero allocations when the level is disabled.
Anti patterns
Don't Use String Interpolation
Don't Skip CloseAndFlush
Don't Log Sensitive Data
Don't Destructure Without Limits
Don't Use the Deprecated Elasticsearch Sink
Decision Guide
Scenario Recommendation
Application logging Serilog with AddSerilog() and appsettings.json
Log storage (development) Seq (free single user) or Aspire Dashboard
Log storage (production) Seq, Elasticsearch (Elastic sink), or OTLP backend
Request logging UseSerilogRequestLogging() (replaces per request noise)
Scoped properties LogContext.PushProperty() in middleware
Log filtering Serilog.Expressions for expression based filtering
High performance paths [LoggerMessage] source generator
Audit trails AuditTo (synchronous, exceptions propagate)
Log levels by environment MinimumLevel.Override per namespace in appsettings
OpenTelemetry integration Serilog.Sinks.OpenTelemetry (no SDK dependency)