基本连线似乎很简单,但是我很难理解如何像往常一样配置 NLog。鉴于以下设置,我将如何设置配置以便将文本文件转储到文件夹中?
应用主机:
LogManager.LogFactory = new NLogFactory();
在应用逻辑中:
ILog log = LogManager.GetLogger(GetType());
log.InfoFormat("Something happened");
一个配置文件,如:
<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="${date:format=HH\:mm\:ss}|${level}|${stacktrace}|${message}" />
<target name="file" xsi:type="File" fileName="${specialfolder:folder=ApplicationData}/logs/App.log"
layout="${date}: ${message}" />
<target name="eventlog" xsi:type="EventLog" source="My App" log="Application"
layout="${date}: ${message} ${stacktrace}" />
</targets>
<rules>
<logger name="*" minlevel="Info" writeTo="file" />
<logger name="*" minlevel="Fatal" writeTo="eventlog" />
</rules>