views:

332

answers:

1

Hi there,

Can anyone help, i have been using log4net with success i basically had a static class (wrapper) in my webproject and i load my config from external file called log4net.config by adding this in assemblyinfo.cs

    // log4net config file
    [assembly: log4net.Config.XmlConfigurator(ConfigFile = "Log4Net.config", Watch = true)]

All good!, now i decided to move my static class to its own class project so i can share my static class (wrapper) with other projects.

The log4net.config is still in the webproject but of course its not getting loaded now, I can tell this because in my static class (now its own project) i am doing

          return LogManager.GetLogger("InfoLogger").IsInfoEnabled;

and IsInfoEnabled returns false, and nothing is being logged, the .config file is not being read...

Remembering the Log4net wrapper (static class) is in its own class project but the .config file is in the web project ihave.. I need it like this because .config can change on a project by project basis but generally the wrapper won't.

Of course i thought i will create an abstract class and just inherit in my webproject and override anything if i need to ... BUT of course you can't inherit static classes or even make abstract..

I am sure someone else has come across this, any ideas? .. any help really appreciated

A: 

You need to put the XmlConfigurator assembly attribute in the class library that wraps log4net. You can keep your log4net.config file in the root directory of your web application.

The XmlConfigurator assembly attribute is read the first time log4net is initialized. Log4net scans the calling assembly to find the attribute.

bryanbcook
yep perfect thanks.. that works
mark smith