Home > Castle Windsor, MonoRail, NLog > Windsor and NLog – Getting the Exception StackTrace

Windsor and NLog – Getting the Exception StackTrace

February 15, 2008 Leave a comment Go to comments

Someone queried the NZ.NET mailing list yesterday about how to get the stack trace out of an exception logged via the NLog logging facility.

Having a quick look at the docs for layout renderers seemed to indicate that the ${exception} layout renderer, however by all accounts that wasn’t working so I’ve thrown together a couple of quick tests and a MonoRail site with Windsor integration enabled demonstrate how to achieve it and make sure it works. You can get the demo from the link below – it is a rar file but as WordPress won’t let me upload rar files, so I have changed the extension to .png. You will need to download it to your machine and change the file extension back to .rar to access the content.

Logging with NLog via Windsor

For those of you who just want to know what the configuration looks like:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
        <targets>
            <target name="debugconsole" xsi:type="Console" layout="${message}"/>
            <target name="errorconsole" xsi:type="Console" layout="${message} [br] Details:${exception:format=type,message,stacktrace:separator=[br]}"/>
        </targets>
        <rules>
            <logger name="*" level="Debug" writeTo="debugconsole"/>
            <logger name="*" level="Error" writeTo="errorconsole"/>
        </rules>
    </nlog>
</configuration>

The targets are both console targets because I temporarily redirect Console.Out to a StringWriter so that I can capture and display the logged data.

Be aware that this demo is built against a copy of the Castle trunk from mid January (all referenced assemblies are included in the download), if you are not seeing the same behaviours in your code, it may be due to differences (or an issue) in the version you are using.

Advertisement
Categories: Castle Windsor, MonoRail, NLog
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

Gravatar
WordPress.com Logo

Please log in to WordPress.com to post a comment to your blog.

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.