<?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" xsi:schemaLocation="http://www.nlog-project.org/schemas/NLog.xsd NLog.xsd" autoReload="true" throwExceptions="false" internalLogLevel="Off" internalLogFile="c:\temp\nlog-internal.log"> <!-- optional, add some variables https://github.com/nlog/NLog/wiki/Configuration-file#variables --> <variable name="myvar" value="myvalue"/> <!-- See https://github.com/nlog/nlog/wiki/Configuration-file for information on customizing logging rules and outputs. --> <targets> <!-- add your targets here See https://github.com/nlog/NLog/wiki/Targets for possible targets. See https://github.com/nlog/NLog/wiki/Layout-Renderers for the possible layout renderers. --> <!-- Write events to a file with the date in the filename. <target xsi:type="File" name="f" fileName="${basedir}/logs/${shortdate}.log" layout="${longdate} ${uppercase:${level}} ${message}" /> --> <target xsi:type="File" name="f" fileName="logs/${shortdate}.log" archiveFileName="logs/archive.{#}.log" archiveEvery="Day" archiveNumbering="Rolling" maxArchiveFiles="30" concurrentWrites="true" keepFileOpen="false" encoding="utf-8"> <layout xsi:type="CsvLayout" delimiter="auto" withHeader="true" > <column name="time" layout="${longdate:universalTime=false}" /> <column name="threadid" layout="${threadid}"/> <column name="level" layout="${level:upperCase=true}"/> <column name="callsite" layout="${callsite:includeSourcePath=true}" /> <column name="message" layout="${message}" /> <column name="stacktrace" layout="${callsite:includeSourcePath=true}" /> <column name="exception" layout="${exception:format=ToString}"/> </layout> </target> <target xsi:type="File" name="c" layout="${threadid} ${uppercase:${level}} ${message} ${callsite} ${exception:format=tostring}" /> </targets> <rules> <!-- add your logging rules here --> <!-- Write all events with minimal level of Debug (So Debug, Info, Warn, Error and Fatal, but not Trace) to "f" <logger name="*" minlevel="Debug" writeTo="f" /> --> <logger name="*" writeTo="f,c" /> </rules> </nlog>NLog这个配置给我怎么加注释说明
时间: 2023-07-06 13:28:17 浏览: 172
在NLog配置文件中添加注释可以使用XML的注释标记`<!-- 注释内容 -->`,例如:
```
<?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"
xsi:schemaLocation="http://www.nlog-project.org/schemas/NLog.xsd NLog.xsd"
autoReload="true"
throwExceptions="false"
internalLogLevel="Off"
internalLogFile="c:\temp\nlog-internal.log">
<!-- 定义变量 -->
<variable name="myvar" value="myvalue"/>
<!-- 定义日志输出目标 -->
<targets>
<!-- 文件日志 -->
<target xsi:type="File" name="f" fileName="logs/${shortdate}.log"
archiveFileName="logs/archive.{#}.log"
archiveEvery="Day"
archiveNumbering="Rolling"
maxArchiveFiles="30"
concurrentWrites="true"
keepFileOpen="false" encoding="utf-8">
<layout xsi:type="CsvLayout" delimiter="auto" withHeader="true" >
<column name="time" layout="${longdate:universalTime=false}" />
<column name="threadid" layout="${threadid}"/>
<column name="level" layout="${level:upperCase=true}"/>
<column name="callsite" layout="${callsite:includeSourcePath=true}" />
<column name="message" layout="${message}" />
<column name="stacktrace" layout="${callsite:includeSourcePath=true}" />
<column name="exception" layout="${exception:format=ToString}"/>
</layout>
</target>
<!-- 控制台日志 -->
<target xsi:type="File" name="c" layout="${threadid} ${uppercase:${level}} ${message} ${callsite} ${exception:format=tostring}" />
</targets>
<!-- 定义日志输出规则 -->
<rules>
<logger name="*" writeTo="f,c" />
</rules>
</nlog>
```
在需要注释的地方添加注释即可,例如:
```
<!-- 定义变量 -->
<variable name="myvar" value="myvalue"/>
<!-- 定义日志输出目标 -->
<targets>
<!-- 文件日志 -->
<target xsi:type="File" name="f" fileName="logs/${shortdate}.log"
archiveFileName="logs/archive.{#}.log"
archiveEvery="Day"
archiveNumbering="Rolling"
maxArchiveFiles="30"
concurrentWrites="true"
keepFileOpen="false" encoding="utf-8">
<layout xsi:type="CsvLayout" delimiter="auto" withHeader="true" >
<column name="time" layout="${longdate:universalTime=false}" />
<column name="threadid" layout="${threadid}"/>
<column name="level" layout="${level:upperCase=true}"/>
<column name="callsite" layout="${callsite:includeSourcePath=true}" />
<column name="message" layout="${message}" />
<column name="stacktrace" layout="${callsite:includeSourcePath=true}" />
<column name="exception" layout="${exception:format=ToString}"/>
</layout>
</target>
<!-- 控制台日志 -->
<target xsi:type="File" name="c" layout="${threadid} ${uppercase:${level}} ${message} ${callsite} ${exception:format=tostring}" />
</targets>
<!-- 定义日志输出规则 -->
<rules>
<logger name="*" writeTo="f,c" />
</rules>
```
阅读全文