Logging & Custom Logging in .NET — ILogger, Serilog, NLog, log4net and Your Own Logger
Levels
Trace < Debug < Information < Warning < Error < Critical · production default Information, framework categories Warning.
Do
Message templates with named properties · LogError(ex, ...) with the exception · scopes/enrichers for context · correlation/trace ids · JSON to stdout in containers · central store + retention + alerts.
Don't
Interpolate log messages · log secrets/PII · log the same exception at every layer · log inside tight loops · block requests on log writes.
Libraries
ILogger (abstraction) · Serilog (structured, sinks, enrichers, UseSerilogRequestLogging) · NLog (nlog.config targets/rules) · log4net (legacy XML appenders) · ELMAH (Framework errors) · OpenTelemetry (logs + traces + metrics).
Custom logger
ILoggerProvider + ILogger · bounded Channel queue · background batch writer · never throw · flush on Dispose · builder.Logging.AddProvider(...).