A production-focused guide to structured logging in .NET covering six key patterns: using LoggerMessage source generators on hot paths for zero-allocation logging, configuring scopes as property bags with explicit provider opt-in, threading a single correlation ID end-to-end via W3C baggage propagation, treating log levels as an operational contract, choosing and tuning the right log sink (Application Insights, Loki, Elasticsearch, Seq), and adopting OpenTelemetry Logs for new services. Includes concrete code examples, a comparison of common sinks, and anti-patterns to avoid such as logging full request bodies and maintaining dual minimum-level configurations.

14m read timeFrom daily-devops.net
Post cover image
Table of contents
The Mental Model: Logs Are Events, Not StringsPattern 1: LoggerMessage Source Generators on Every Hot PathPattern 2: Scopes Are for Context, Not for StringsPattern 3: One Correlation ID, Threaded End-to-EndPattern 4: Levels Are a Contract, Not a PreferencePattern 5: The Sink Is Part of the ArchitecturePattern 6: OpenTelemetry Logs Where You CanWhat I Do Not Recommend
4.6K Impressions