2012-04-23 57 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