Log4Net Logs Not Generated, No AssemblyInfo.cs, WebSite Project

Today I had to implement Log4Net logging for my website. Using the lessons I had learned in my previous Journey Of Pain setting up log4net for a Console Application (see previous post) I figured this would be a doddle. Not so. Once again my logger failed to find any appenders.

Because my site is a VS WebSite Project and not a Web Project, it does not have an AssemblyInfo file, which is the normal place you would put your XmlConfigurator. So I put the call to XmlConfigurator.Configure in Global.asax Application_Start as suggested by Apache. No dice. Ot should I say once again, no Appenders and definitely no logging.

Googling hither and thither the core temperature of my liver reached Chernobyl proportions before I staggered blindly into the Googleistic revelation that log4net default configuration has a bug where AssemblyInfo is not present, as is the case for all Website projects (as opposed to Web Projects).

To overcome this bug you must move your log4net config to an external file and use the magic ApplicationSetting key ‘log4net.Config’ in web.config. The Stack Overflow contribuor Precipitous provided the necessary balm to my self-combusting liver in his post to Stack Overflow on the subject log4net in external file does not work.

The fix, in summary, create an external log4net config file, but leave the log4net section handler in your web.config, and add this Application Key add key=”log4net.Config” value=”your-path-here” .

Now relax, settle back, and watch this video of the Prime Minister Of Australia eating his ear wax.

Advertisements

Tags: ,

Leave a Reply

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

WordPress.com Logo

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

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s


%d bloggers like this: