Configuring NLog to log exceptions in an XML output?

As far as I can tell, the Log4JXmlEventLayout has some properties associated with it (stack trace-ish information, calling class, time, etc), but that's about it. I've looked into how to include additional information, but it seems as if that's not possible.

A possible configuration looks like this:

<target name ="xmlFile" xsi:type="File"
                fileName="${tempdir}/${processname}/log.xml"
                archiveFileName="${tempdir}/${processname}/archive/log_{#####}.xml"
                archiveAboveSize="10000000"
                layout="${log4jxmlevent:includeSourceInfo=true:includeCallSite=true:includeMDC=true:appInfo=true:includeNDC=true:includeNLogData=true}"/>

However, I've found that only NLog 2.0 will actually make use of attributes like "includeSourceInfo". It appeared to me that in NLog 1.0, when these were set to true, the resulting xml contained only the date, level, and message.

One reason not to use Log4JXmlEventLayout is that it doesn't do anything with exceptions, i.e. if you call

logger.ErrorException("This shouldn't happen", exception);

the logger will write down "This shouldn't happen", but the exception info is gone.

Maybe it would be possible to create a custom xml wrapper around the data you want. I haven't done so, but I'm thinking about it simply due to the limitations around the Log4JXmlEventLayout.

Tags:

Xml

Nlog