liveBook · Manning

outputTemplate

As explained in Building Web APIs with ASP.NET Core

An output template is a format specification that determines how log events are rendered as text.

An output template specifies how each log event is rendered as text. In a Serilog file sink, it controls which event values appear and how they are arranged. section 7.4.5

Configure it on the sink with a template string containing message-template properties such as Timestamp, Level, MachineName, ThreadId, Message, NewLine, and Exception. section 7.4.5

Include machine and thread information

lc.WriteTo.File("Logs/log.txt", outputTemplate: "{Timestamp:HH:mm:ss} [{Level:u3}] " + "[{MachineName} #{ThreadId}] " + "{Message:lj}{NewLine}{Exception}", rollingInterval: RollingInterval.Day); section 7.4.5

Verify the configuration by:

  • Launching the project in Debug mode and waiting for it to load. section 7.4.5
  • Opening the Logs folder and checking the daily log<yyyyMMdd>.txt file. section 7.4.5
  • Confirming entries show the timestamp, abbreviated level, machine name, thread ID, message, and exception text in the configured order. section 7.4.5
lc.WriteTo.File("Logs/log.txt",
outputTemplate:                 #1
"{Timestamp:HH:mm:ss} [{Level:u3}] " +
"[{MachineName} #{ThreadId}] " +
"{Message:lj}{NewLine}{Exception}",
        rollingInterval: RollingInterval.Day);

Inspect the complete file-sink configuration and see how the template combines timestamp, level, enriched properties, message text, line breaks, and exceptions. section 7.4.5

How Building Web APIs with ASP.NET Core covers it

How deep it goes
Defines template properties and formatting, then verifies rendered files, but defers broader Serilog syntax.
Examples
Uses daily log files containing timestamps, levels, machine names, thread IDs, messages, and exceptions.
What it assumes
Assumes basic application logging and introduces sink templates alongside enriched log properties.
What you can do after
Operate/configure a Serilog file sink and verify that enriched log properties appear in the desired order.
How it connects
Connects Serilog file sinks with enrichers, rolling intervals, and message-template syntax.

This explainer was generated by Manning's knowledge graph from the text of Building Web APIs with ASP.NET Core. The section links point to the parts of the book it draws on.