本文介绍了如何在 serilog RollingFile outputTemplate 中输出事件源类名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 配置中用于接收器的 RollingFile.outputTemplate 如下:

The RollingFile.outputTemplate that I am using for my sink in <appSettings> configuration is as below:

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

我得到的输出日志:

19:55:10 [信息] Application_Start...

但是,我还想从生成日志的位置输出类名称(源),例如 -

However, I want to also output the Class Name (source) from where the Log was generated, like -

19:55:10 [信息] [Global.asax.cs] Application_Start...

我应该为价值"添加什么?我添加了[来源],但不起作用.

What should I add to the "value"? I added [Source] but is not working.

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

推荐答案

属性名叫做 SourceContext - 所以:

The property name is called SourceContext - so:

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

这篇关于如何在 serilog RollingFile outputTemplate 中输出事件源类名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-16 13:14