NLog: What is layout and layout-renderers?
我是NLog的新手,我对layout和layout-renderers感到困惑。
我看到了以下代码\页面:
https://github.com/NLog/NLog/wiki/Configuration-API
https://github.com/NLog/NLog/wiki/CsvLayout(xml)
https://github.com/NLog/NLog/wiki/Exception-Layout-Renderer(类似于第一个)
我首先了解(日志消息的格式),但是我不了解第二和第三。
- 布局用于定义渲染输出的布局,例如CSV,JSON,XML(NLog 4.6+)或普通布局(默认)。 NLog当前有5种布局(包括默认布局):https://nlog-project.org/config/?tab=layouts
-
布局渲染器正在渲染值,例如消息,异常,进程ID等。也称为"模板标记"。布局呈现为
${something} 。 NLog中大约有100个布局渲染器,但也有一些第三方布局渲染器。参见https://nlog-project.org/config/?tab=layout-renderers
您可以将布局视为组合布局渲染器的一种方法。默认布局有点隐藏,但其他布局应使其更清晰。请参阅下面的示例。
一些例子:
默认布局
这是具有4个布局渲染器(日期,级别,消息,异常)的默认布局。
JSON布局
具有JsonLayout且具有相同4个布局渲染器的文件目标:
1 2 3 4 5 6 7 8 | <target name='jsonFile' type='File' fileName='log.json'> <layout type='JsonLayout'> </layout> </target> |
这将使用
CSV相同,但随后创建CSV文件(或CSV到数据库等)。
异常布局渲染器:$ {exception}
(另请参阅https://github.com/NLog/NLog/wiki/Exception-Layout-Renderer)
这是用于呈现异常,因为异常是与NLog中的消息分开捕获的。另请参阅如何适当的日志异常