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?
Context Properties The log4net contexts store properties, i.e. name value pairs. The name is a string the value is any object. A property can be set as follows: log4net.
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!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With