我已经将NLog添加到我的项目中,并且在开发环境中,它工作得很好。
我创建了一个安装文件来部署我的应用程序。NLog.config文件在安装项目中未显示为依赖项。因此,我将其添加为一个文件,并且在部署时,它与exe文件和App.config位于同一目录中。
它不做任何日志记录。我也不知道原因。以下是配置文件:
<?xml version="1.0" encoding="utf-8" ?>
<?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">
<variable name="day" value="${date:format=dd}" />
<variable name="month" value="${date:format=MM}" />
<variable name="year" value="${date:format=yyyy}" />
<variable name="verbose" value="${longdate} | ${level} | ${message} | ${exception:format=tostring,message,method:maxInnerExceptionLevel=5:innerFormat=shortType,message,method}}" />
<targets>
<target name="logfile" xsi:type="File" fileName="${basedir}/Logs/${year}${month}${day}.log" layout="${verbose}" />
</targets>
<rules>
<logger name="*" minlevel="Error" writeTo="logfile" />
</rules>
</nlog>任何帮助都是最好的。干杯!
发布于 2012-04-24 03:28:56
将您的NLog配置放在yourapp.exe.config文件中。如下所示:
<configuration>
<configSections>
<section name="nlog" type="NLog.Config.ConfigSectionHandler, NLog"/>
</configSections>
<nlog>
<variable name="day" value="${date:format=dd}" />
...
<targets>
<target name="logfile" xsi:type="File" .../>
</targets>
<rules>
<logger name="*" minlevel="Error" writeTo="logfile" />
</rules>
</nlog>
</configuration>发布于 2012-04-25 19:15:38
https://stackoverflow.com/a/8881521/438760是否将NLog.config的“复制到输出目录”属性设置为“始终复制”?
发布于 2012-04-24 03:30:09
我猜双重xml版本语句(第1行和第2行)是一个复制/粘贴问题……
这可能是一个愚蠢的问题,但是您将minLevel设置为Error。您是否真的遇到了会被记录的错误,或者您是否尝试过将其降低为info或debug?
https://stackoverflow.com/questions/10274545
复制相似问题