<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="nlog" type="NLog.Config.ConfigSectionHandler, NLog"/>
</configSections>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<targets>
<target name="file" xsi:type="File"
layout="${longdate} ${logger} ${message}${exception:format=ToString}"
fileName="${basedir}/logs/${shortdate}.log"
keepFileOpen="true"
encoding="utf-8" />
<target name="f1" xsi:type="File" fileName="file1.txt"/>
<!--layout代表日志的格式-->
<target name="f2" xsi:type="File" fileName="file2.txt" layout="${date:format=yyyyMMddHHmmss} ${callsite} ${level} ${message}"/>
<target name="n1" xsi:type="Network" address="tcp://localhost:4001"/>
<target name="ds" xsi:type="OutputDebugString"/>
</targets>
<rules>
<!--writeTo使用哪个target-->
<logger name="*" minlevel="Debug" writeTo="f2" />
<logger name="mylog" minlevel="Debug" writeTo="f1" />
<logger name="test" levels="Debug,Error" writeTo="n1"/>
</rules>
</nlog>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
</startup>
</configuration>
直接复制 ,更改writeTo属性就 可以 使用。
转载于:https://www.cnblogs.com/zhaotianff/p/9219660.html