Layouts
Layouts是许多的target都可以配置的特性。他用于设定日志输出的格式。有许多预定的'macros' 和Layout renderers配置。比如: ${machinename}就是一个layout renderer.
默认布局
如果一个target有一个layout特性。你就可以自定义布局。默认的布局是:
${longdate}|${level:uppercase=true}|${logger}|${message}
预定义的 Layouts
- CsvLayout - 生成CSV格式的文件
- LayoutWithHeaderAndFooter - 输出的日志具有页头和页脚
- Log4JXmlEventLayout - 输出Log4j兼容的XML文件
- SimpleLayout - 通过Layout Renderer来渲染出日志文本
例子:
simple layout:
layout="${machinename} ${message}"
配置文件如下:
<? xml version = "1.0" encoding = "utf-8" ?> < nlog xmlns = "http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance" > < targets > < target name = "console" xsi:type = "ColoredConsole" layout = "${machinename} ${message}" /> </ targets > < rules > < logger name = "*" minlevel = "Trace" writeTo = "console" /> </ rules > </ nlog > |