Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

log4net configuration with [assembly:]

I was curious how the following line works for configuring log4net in an assembly:

[assembly: log4net.Config.XmlConfigurator(Watch=true)]

I'm guessing this gets called sometime before the runtime invokes "main()" but when does this occur, and what are the implications? Are there other frameworks/libraries that use this assembly attribute for loading an initial context like this? Are there any advantages/disadvantages for doing something like this, as opposed to calling a "Configure" method in main()?

like image 339
Andy White Avatar asked Mar 15 '09 23:03

Andy White


People also ask

Where is log4net config?

You can configure the log4net. config file to create log files. The file is located in the webroot\App_data directory of the installation.


1 Answers

The advantages of doing this are that the code is initialised in advance of your main code and in advance of the static initialisation.

This means that you can, for example, use log4net logging within a static-constructor. Without a way to pre-initialise log4net, in the static constructor you'd never know for certain that the code has been initialised correctly.

This area doesn't seem to be very well documented (or easy to find anyway) but I assume that the initialisation of called methods is performed at Assembly-load time.

like image 113
Ray Hayes Avatar answered Sep 23 '22 01:09

Ray Hayes