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
