Serilog 2.0 short level names
Serilog renders plain text logs in a simple format with each event’s timestamp, level and message:
2016-07-18 08:53:53.691 +10:00 [Information] Starting up at 07/18/2016 08:53:53
2016-07-18 08:54:23.716 +10:00 [Error] Timeout reached while waiting for input
If you find the full-width level names like Information
and Error
awkward to read, you can instruct Serilog 2.0 to write fixed-width names instead:
2016-07-18 08:53:53.691 +10:00 [INF] Starting up at 07/18/2016 08:53:53
2016-07-18 08:54:23.716 +10:00 [ERR] Timeout reached while waiting for input
This is done by overriding the sink’s outputTemplate
and specifying a format like u3
for the Level
property:
Log.Logger = new LoggerConfiguration()
.WriteTo.File("log.txt",
outputTemplate: "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level:u3}] {Message}{NewLine}{Exception}")
.CreateLogger();
Level formats consist of either u
(for uppercase) or w
(lowercase) and a number of characters. The level names are abbreviated so that Warning
is shortened to WRN
rather than WAR
for example.
All plain text sinks support this option, including Console, File, RollingFile, and Trace. Thanks are due to Antony Koch for driving this feature.