2017-05-31 8 views
2

NLogを使用して内部例外メッセージをログに記録しようとしています。NLog内部例外ログオン

<target name="errors" xsi:type="File" layout="${longdate}${newline} 
     - Exception Message: ${exception:format=Message}${newline} 
     - InnerException Message: ${exception:innerExceptionSeparator=TEXT}${newline}" 
     fileName="\Logs\errors-${shortdate}.log" 
     concurrentWrites="true" /> 
    </targets> 

私はNLog.configファイルの両方Exception MessageInnerException Messageラインに同じメッセージSee the inner exception for detailsを得ている:これは私のNLog.configファイルの一部です。

答えて

3

これが私の仕事:

<target name="errors" xsi:type="File" layout=" 
      ${message} 
      ${onexception:EXCEPTION OCCURRED\: 
      ${exception:format=type,message,method:maxInnerExceptionLevel=5:innerFormat=shortType,message,method}}" 
      fileName="\Logs\errors-${shortdate}.log" 
      concurrentWrites="true" 
      /> 
    </targets> 
+0

レイアウトはいくつかの行でログメッセージがコンソールウィンドウの一番左の位置から開始される原因となります。 '$ {message} 'と行開始の間のスペース(タブ)はログに表示されます – oleksa

0

を別の可能性は、内部例外の間に新しい行を追加することですinnerExceptionSeparatorが何らかの特別な方法で解析されていないため、XMLで改行&#xD;&#xAを使用することであり、それがあるとしてロードされます書きました。だからinnerExceptionSeparator=${newline}は動作しません。

layout="${message}${onexception:${newline}${exception:maxInnerExceptionLevel=10:innerExceptionSeparator=&#xD;&#xA;&#x9;:format=shortType,message}} 

この

は、内部例外テキストは新しい行から開始し、

しかし、これはILogger.Error(Exception, string)方法が使用されている場合にのみ機能タブ文字でインデントされるようになります。 ILogger.Error(Exception)はこのレイアウトを無視します

+0

私はこの解決策をテストします...ありがとう –

関連する問題