SharePoint and Log4Net


I'm looking for best practices to integrate log4net to SharePoint for web request, feature activation and all timer stuff.

I have several subprojects in my farm, and I would like to have only one Log4Net.config file.

Not only I need to configure log4net for the web application, which is easy to do (I use global.asax, and a log4net.config file, so I can modify log settings withtout reloading the webapp), but I also need to log asynchronous events:

  • Event Handler (like ItemAdded)
  • Timer Jobs

Best Solution

I implemented this recently and came up with a solution that worked for me.

Deploy your log4net config file to the 12 hive and the log4net dll into the GAC using a globally scoped solution. Then in your application code explicitly initialize log4net from the location of your global file. This allows you to log feature receiver, timer jobs and web application code.

[assembly: log4net.Config.XmlConfigurator(ConfigFile = 
    @"C:\Program Files\Common Files\Microsoft Shared\" + 
    @"Web Server Extensions\12\CONFIG\log4net.config", Watch = true)]

see here