Serilog logging setup
Skill StefanTheCode/dotnet-ai-toolkit/skills/serilog-logging-setup
Set up structured logging with Serilog in ASP.NET Core — JSON output, enrichers, request logging, log levels, and sinks — correlated with traces. Use this skill whenever the user wants Serilog, structured logging, JSON logs, request logging, log enrichment, log sinks (Seq/Elastic/console), or asks "how do I add logging / set up Serilog / get structured logs". Always use this skill for Serilog/structured-logging requests; it wires production-shaped logging, not just Console.WriteLine.From its SKILL.md
npx -y skills add StefanTheCode/dotnet-ai-toolkit --skill serilog-logging-setupAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
One thing to look at
- 18 stars18 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.
SKILL.md
2.9 KB, as published. Nobody here has run it
Serilog Structured Logging Setup
Wire up Serilog in ASP.NET Core for structured (JSON) logs with enrichers, request logging, sensible levels, and sinks — correlated with your traces.
Input — point it at your project
Works on a target: a project or GitHub URL. Inspect current logging: grep -rn "UseSerilog\|ILogger\|Log.Logger\|AddSerilog" --include=*.cs <target>. If OTel is present, wire log/trace correlation.
Packages + wiring
dotnet add package Serilog.AspNetCore
dotnet add package Serilog.Sinks.Seq # or Console/Elastic/etc.
builder.Host.UseSerilog((ctx, services, lc) => lc
.ReadFrom.Configuration(ctx.Configuration)
.ReadFrom.Services(services)
.Enrich.FromLogContext()
.Enrich.WithMachineName()
.Enrich.WithProperty("service", "orders")
.WriteTo.Console(new RenderedCompactJsonFormatter()) // structured JSON
.WriteTo.Seq(ctx.Configuration["Seq:Url"]!));
app.UseSerilogRequestLogging(); // one tidy log line per request instead of the default noise
Structured logging done right
// GOOD: message template + properties (queryable)
logger.LogInformation("Order {OrderId} placed by {CustomerId} for {Total}", id, customerId, total);
// BAD: interpolated string (loses structure)
logger.LogInformation($"Order {id} placed");
What to set
- Levels —
Informationdefault,Warningfor noisy frameworks,Debugonly in dev. Configure viaappsettings. - Enrichers — machine, environment, and a correlation/trace id (see
correlation-id-middleware). - Request logging —
UseSerilogRequestLoggingfor one structured line per request with status + duration. - Trace correlation — include
TraceId/SpanIdso logs link to traces.
Principles
- Message templates, not interpolation — structure is the whole point of structured logging.
- Don't log secrets/PII. Be deliberate about what goes into properties.
- Log at the right level;
Informationfor business events,Errorwith the exception object (notex.Message). - One sink for local (console JSON), one for aggregation (Seq/Elastic/Loki).
How to use it & best prompts
"Set up Serilog with JSON logs and Seq", "add request logging", "correlate my logs with traces", "fix my logging to be structured". Pairs with opentelemetry-setup and correlation-id-middleware.