views:

920

answers:

2

I have log4net running on my AsP.NET site. I'm able to log messages to my DB Table, but it isn't logging the ThreadContext properties. For example:

ThreadContext.Properties["Url"] = HttpContext.Current.Request.Url.ToString();
ThreadContext.Properties["HttpReferer"] = HttpContext.Current.Request.ServerVariables["HTTP_REFERER"];

My log4net.config adds those values as parameters into my SQL DB table:

<parameter>
    <parameterName value="@URL"/>
    <dbType value="String"/>
    <size value="512"/>
    <layout type="log4net.Layout.PatternLayout">
     <conversionPattern value="%property{log4net:Url}"/>
    </layout>
</parameter>
<parameter>
    <parameterName value="@HttpReferer"/>
    <dbType value="String"/>
    <size value="512"/>
    <layout type="log4net.Layout.PatternLayout">
     <conversionPattern value="%property{log4net:HttpReferer}"/>
    </layout>
</parameter>

As I debug, I see that those ThreadContext properties are being set, but they aren't getting into the DB.

How can I get that to work?

A: 

Can you turn on log4net verbose/debug/show sql to see what its doing at that level? Is there perhaps another bit of config thats needed to tie it all together?

Chris Kimpton
+2  A: 

So, it turns out the config was to blame. It was slightly wrong:

Original:

<conversionPattern value="%property{log4net:HttpReferer}"/>

Changed:

<conversionPattern value="%property{HttpReferer}"/>

I had to take out the "log4net:" inside of property.

What's odd is that one property still required log4net:propertyName. I have absolutely no idea why it works this way, but that's the fix that worked!

sgwill