serilog
Installation
SKILL.md
Serilog
Core Principles
- 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.
AddSerilog()overUseSerilog()— Usebuilder.Services.AddSerilog()(the modern API) instead ofbuilder.Host.UseSerilog(). It integrates with DI services viaReadFrom.Services(services).- 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. - 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
using Serilog;