NLog Inner Exception Logging

Viewed 9842

I'm trying to log inner exception messages by using NLog. This is a piece of my NLog.config file:

    <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>

I'm getting the same message See the inner exception for detailsfor both Exception Message and InnerException Message lines of NLog.config file.

2 Answers

another possibility is to add new line between inner exception is to use linebreak &#xD;&#xA in the xml, since innerExceptionSeparator is not parsed in some special way and is loaded as it is written. So innerExceptionSeparator=${newline} will not work.

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

this will cause inner exception text to be started from the new line and indented by tab character

however this works only if ILogger.Error(Exception, string) method is used. ILogger.Error(Exception) ignores this layout

Related