NLog LogException seems to ignore the exception

后端 未结 2 520
别那么骄傲
别那么骄傲 2021-02-05 01:25

LogException or any of the derived functions like ErrorException etc. seem to totally ignore the exception parameter passed in.

Am I missing a

相关标签:
2条回答
  • 2021-02-05 01:56

    Add or replace the ${exception} tag in the layout config to ${exception:format=tostring}

     <targets>
        <target name="errorLogFile" xsi:type="File" fileName="errors.txt" 
                layout="${message} ${exception:format=tostring}"/>
    </targets>
    
    0 讨论(0)
  • 2021-02-05 02:06

    Building on @Niki's answer, this will give you pretty close to what log4net will do

    fileName="${basedir}/logs/${shortdate}.log" layout="${longdate}|${level:uppercase=true}|${logger}|${message}${onexception:inner=${newline}${exception:format=tostring}}"
    
    0 讨论(0)
提交回复
热议问题