Search code examples
serilogrollingfilesink

Serilog - Possible to Change DateTime/Timestamp Format in RollingFile Sink


The Current Output of RollingFile Sink for Date time is as follows

2015-04-06 18:40:54.400 +10:00 [Information] Hello World!

Is there anyway to remove the TimeZone Offset? +10:00. To Achieve the following output;

2015-04-06 18:40:54.400 [Information] Hello World!

In my case, the timezone offset is superfluous fluff which is just cluttering my Text Log.


Solution

  • You can specify the outputTemplate parameter to the .RollingFile() configuration method:

    .WriteTo.RollingFile(
        outputTemplate: "{Timestamp:yyyy-MM-dd HH:mm:ss.fff} [{Level}] {Message}{NewLine}{Exception}")