2012-04-23 60 views
4

我已将NLog添加到我的项目和开发环境中,它工作正常。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> 

任何帮助将是巨大的。干杯!

回答

4

将您的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> 
+0

xsi标签卡住一个错误。我怎样才能在那里获得架构? – onefootswill 2012-04-23 23:06:14

+0

粘贴您自己的配置,xmlns属性和全部。为了可读性,我删除了一些东西(因此是点)。也;见例如http://snipplr.com/view/24560/和http://nlog-project.org/wiki/Visual_Studio_support – BaBu 2012-04-24 06:07:57

+0

这东西看起来不错。我会着手解决这个问题。 – onefootswill 2012-04-26 03:42:10

0

我猜双XML版本声明(1号线和2)是一个复制/粘贴问题....

可能是一个愚蠢的问题,但你有定义的MinLevel值到错误。你真的遇到了会被记录的错误,或者你是否尝试将这些信息降低到信息或调试?

+0

这是一个粘贴错误,我故意抛出一个异常,在开发条件(IDE)下记录得很好。 – onefootswill 2012-04-23 23:08:15