2017-12-01 4 views
0

ここに私のNlog.Configコードがあります。NLogは例外または他のテキストを記録しません

<nlog> 
    <variable name="logFilePath" value="C:\NLog\IDG-${shortdate}.log" /> 
    <targets> 
    <target name="logfile" 
      xsi:type="File" 
      fileName="${logFilePath}" 
      layout="${longdate} LEVEL=${level:upperCase=true}: ${message}" 
      keepFileOpen="true" /> 
    </targets> 
    <rules> 
    <logger name="*" minlevel="Debug" writeTo="logfile" /> 
    <logger name="*" minlevel="Info" writeTo="logfile" /> 
    <logger name="*" minlevel="Warn" writeTo="file"/> 
    </rules> 
</nlog> 

私のクラスに
private static Logger logger = LogManager.GetCurrentClassLogger(); 

これを定義していますし、私のようにエラーをログに記録しています:に任意のより良い方法があるかどうか誰も私を提案してくださいすることができ

catch (Exception ex) 
      { 
       logger.Error(ex.Message,"test"); 
      } 

これを行うと、私は、ファイルが目的のフォルダに記録されているのを見ません。

+0

を削除あなたのログ –

+0

私が見た例は、/の代わりにファイルパスに/を使用しているようです。多分それを試してみてください russelrillema

答えて

0

設定セクションを正しく参照していないようです。このような何かにあなたのメインの設定ファイルを変更してみてくださいし、[troublesoot](https://github.com/nlog/NLog/wiki/Configuration-file#troubleshooting-logging)にしてみNlog.Config

<?xml version="1.0" encoding="utf-8" ?> 
<configuration> 
    <configSections> 
    <section name="nlog" type="NLog.Config.ConfigSectionHandler, NLog" /> 
    </configSections> 
    <startup> 
     <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.2" /> 
    </startup> 
    <nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 
    <variable name="logFilePath" value="C:\temp\output.log" /> 
    <targets> 
     <target name="logfile" 
       xsi:type="File" 
       fileName="${logFilePath}" 
       layout="${longdate} LEVEL=${level:upperCase=true}: ${message}" 
       keepFileOpen="true" /> 
    </targets> 
    <rules> 
     <logger name="*" minlevel="Debug" writeTo="logfile" /> 
     <logger name="*" minlevel="Info" writeTo="logfile" /> 
     <logger name="*" minlevel="Warn" writeTo="file"/> 
    </rules> 
    </nlog> 
</configuration> 
+0

ありがとう@russelrillema –

関連する問題