Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

[Edit]
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
  • ...
like image 361
Nico Avatar asked Oct 20 '08 19:10

Nico


1 Answers

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 http://www.codeproject.com/KB/sharepoint/SharepointLog4Net.aspx

like image 130
TheCodeKing Avatar answered Sep 28 '22 03:09

TheCodeKing