4

Closed

log4jxmlevent does not render Exception

description

When using the log4jxmlevent no Exception is rendered to the logfile.
 
I tried:
Config of Target:
<target name="logfile" xsi:type="File" fileName="C:\Logfile_${shortdate}.xml" keepFileOpen="false" layout="${log4jxmlevent:includeSoucreInfo=true:includeCallSite=true:includeMdc=true:includeNdc=true:indentXml=true}"/>
 
In Code:
Log.Error("Test", new Exception("Ex1", new Exception("Inner Ex1")));
Log.ErrorException("Test2", new Exception("Ex2", new Exception("Inner Ex2")));
 
In both cases the logfile only contains the message "Test" or "Test2" but not the exception.
Closed Oct 7, 2012 at 6:49 PM by Xharze
Moved to https://github.com/NLog/NLog/issues/132

comments

Anjdreas wrote Apr 4, 2012 at 8:29 AM

Great work georgiosd, I was googling a ton before I realized the problem was NLog itself. I even made a stackoverflow post for it: http://stackoverflow.com/questions/9990591/how-to-log-exceptions-with-network-targets-in-nlog

georgiosd wrote Apr 4, 2012 at 10:57 AM

Credit to the developer of Log4View who pointed this out to me! :)

Anjdreas wrote Apr 4, 2012 at 12:05 PM

I was not able to make this work with NLogViewer or Chainsaw targets though. At least no exception/stacktrace is showing up in Sentinel or Log2Console log viewers. I recompiled NLog with your patch, but it didn't seem to make any difference.

georgiosd wrote Apr 4, 2012 at 12:56 PM

This only applies to the log4jxmlevent layout used in the example above - this is the one that Log4View requires to work. I don't know why it doesn't work with NLogViewer or Chainsaw.

I would suggest that you go for Log4View - it's free for personal use and actively developed, which is not the case for any of the other targets AFAIK.
Or, if you have an enterprise application, check loggly.com - I've made an NLog target for it and migrating there.

PS: Not my patch, just thought I'd mention it