Practical structured logging examples for .NET and ASP.NET Core using Serilog. Learn how to move beyond plain-text logs with queryable key-value properties, how to use logging scopes to add contextual information across multiple log entries, and how to configure Serilog entirely from appsettings.json without touching code.
| Project | Description |
|---|---|
AspNetCoreSerilogFromAppSettingsExample |
Demonstrates configuring Serilog sinks, enrichers, and minimum log levels entirely through appsettings.json — no code-based configuration needed |
LoggingScopeExample1 |
Introduces ILogger.BeginScope() to attach contextual properties (e.g. request ID, user ID) to every log entry within a scope block |
LoggingScopeExample2 |
Shows a more advanced logging scope pattern with structured scope state objects |
VibeCodeSerilogAspNetCore |
A vibe-coded ASP.NET Core Web API with full Serilog integration — generated with AI assistance to show real-world structured logging setup |
- Clone the repository
- Open
StructuredLoggingExamples.slnxin Visual Studio 2022+ or usedotnet run - Run any project:
dotnet run --project AspNetCoreSerilogFromAppSettingsExample - Observe structured log output in the console with enriched properties
- Structured Logging — logs as queryable key-value pairs instead of flat strings, enabling filtering and aggregation in tools like Seq or Application Insights
- Serilog — the most popular structured logging library for .NET with a rich sink ecosystem
- Logging Scopes —
ILogger.BeginScope()attaches ambient context (correlation IDs, user info) to all log entries within a code block - AppSettings Configuration — configure Serilog sinks, enrichers, and levels via
appsettings.jsonfor environment-specific logging without redeployment
If you found this useful and you want to learn more about C#, .NET, and software engineering, subscribe to the free Dev Leader Weekly newsletter:
Subscribe to Dev Leader Weekly
- All Links
- Website - Dev Leader
- YouTube - Dev Leader
- YouTube - Dev Leader Path To Tech
- YouTube - Dev Leader Podcast
- YouTube - CodeCommute
- Newsletter - Dev Leader Weekly
- LinkedIn - Nick Cosentino
- GitHub - ncosentino
- Twitter/X - Dev Leader
- Threads - Dev Leader
- Bluesky - Dev Leader
- Mastodon - Dev Leader
- Facebook - Dev Leader
- TikTok - Dev Leader
- Twitch - Dev Leader
- Stack Overflow - Nick Cosentino
Powered by BrandGhost 👻



