I'm trying to use a couple of enrichers (machine name and thread ID for now) in conjunction with a rolling file sink and a Loggly sink. Whilst the Loggly events correctly contain the machine name and thread ID properties, I can't see these in the rolling file events.
Here is my xml/code configuration:
<add key="serilog:minimum-level" value="Information" />
<add key="serilog:write-to:RollingFile.pathFormat" value="C:\Foo\bar-{Date}.txt" />
<add key="serilog:using" value="Serilog.Sinks.Loggly" />
<add key="serilog:write-to:Loggly.inputKey" value="redacted Loggly key" />
new LoggerConfiguration()
.ReadAppSettings()
.Enrich.WithMachineName()
.Enrich.WithThreadId()
.CreateLogger()
Did anyone manage to do this? Could this behaviour be by design or are these enrichers not supported for rolling file sinks?
The machinename and threadid are added as properties to all log events. They are not in the messageformat so serilog does not convert them to a textual representation. They will however be send to the sinks. The Loggly sink will pick all the properties (including the thread id etc) and convert those to something Loggly understands (as it can accept any kind of data).
If you want the RollingFile sink to also output the machinename etc, you need to adjust te output template. So setting it to for example this:
outputTemplate: "{Timestamp:HH:mm} [{Level}] {MachineName} ({ThreadId}) {Message}{NewLine}{Exception}"
See also https://github.com/serilog/serilog/wiki/Configuration-Basics#enrichers
Since the rolling file sink has no way to output all the properties, you only get the rendered message which by default does not contain those properties.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With