Structured events in C#
Log properties as data, not string soup.
using Serilog;
Log.Logger = new LoggerConfiguration()
.MinimumLevel.Debug()
.WriteTo.Console()
.CreateLogger();
// properties are named data, not string soup
Log.Information("Deployed {Service} in {Elapsed}ms", "api", 412);
Log.Warning("Disk at {Percent}% on {Host}", 91, "web-2");
Log.Debug("Cache warmed with {Count} entries", 1024);
Log.CloseAndFlush();
How it works
- The logger is configured once: minimum level, then sinks.
{Service}and{Elapsed}are named properties, not placeholders.CloseAndFlushdrains the pipeline before the process exits.
Keywords and builtins used here
newusing
The run, in numbers
- Lines
- 13
- Characters to type
- 359
- Tokens
- 66
- Three-star pace
- 90 tpm
At the three-star pace of 90 tokens a minute, this run takes about 44 seconds.
Step 1 of 2 in Logging with Serilog, step 6 of 16 in The open ecosystem.