Monday, August 6, 2007

Setup log4net for .NET 2.0

I found out that I have to use for a project log4net to log all the messages. So, being my first en counting with it I decide to write some things about it.

Here there is a great description of how to set up log4net.
So remember to make it work for a webapp, using configurations from a file you have to add fallowing line in the global.asax.cs inside Application_Start():

log4net.Config.XmlConfigurator.Configure()



If you specify the configuration in a different file then web.config then you have to add the fallowing attributes to the class (for a webapp in the global.asax.cs)


// We want this assembly to have a seperate logging repository
to the
// rest of the application. We will configure this repository
seperatly.
[assembly: log4net.Config.Repository("Test")]

// Configure logging for this assembly using the
'Test.dll.log4net' file
[assembly: log4net.Config.XmlConfigurator
(ConfigFileExtension = "log4net", Watch = true)]