How to output the class name event source in serilog RollingFile outputTemplate?

RollingFile.outputTemplate that I use for my shell in the <appSettings> configuration is shown below:

 <add key="serilog:write-to:RollingFile.outputTemplate" value="{Timestamp:HH:mm:ss} [{Level}] {Message}{NewLine}{Exception}" /> 

The output log I get as:

19:55:10 [Information] Application_Start...

However, I also want to output the name of the class (source) from which the log was created, for example -

19:55:10 [Information] [Global.asax.cs] Application_Start...

What needs to be added to value? I added [Source] , but it doesn’t work.

value = "{Timestamp: HH: mm: ss} [{Level}] [Source?] {Message} {NewLine} {Exception}"

+6
source share
1 answer

The name of the property is called SourceContext - so:

 value="{Timestamp:HH:mm:ss} [{Level}] [{SourceContext}] {Message}{NewLine}{Exception}" 
+11
source

Source: https://habr.com/ru/post/981410/


All Articles