typestar

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

  1. The logger is configured once: minimum level, then sinks.
  2. {Service} and {Elapsed} are named properties, not placeholders.
  3. CloseAndFlush drains the pipeline before the process exits.

Keywords and builtins used here

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.

Type this snippet

Step 1 of 2 in Logging with Serilog, step 6 of 16 in The open ecosystem.

← Previous Next →