Class project does not load log4net.config from main project

I have log4net Wrapper and log4net dll in my own class project and I added the following to the assemblyinfo.cs of the class project

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

      

So my main project has a log4net.config file and my main project has a log running.

I also have another class project (nothing to do with log4net) that my main project (where the logging works) calls the class project. So I go into a new class project and have to write something, but IsDebugEnabled returns false. This is the line

      LogManager.GetLogger("DebugLogger").IsDebugEnabled;

      

So the main project (webproject) that is referencing my LOGGING class returns TRUE, but the class project I am calling from my main project returns false.

It looks like the class project is not reading log4net

Any ideas?

+2


source to share


2 answers


If I follow correctly, your setup would be like this:

Web project (web.config and log4net.config)

  • Links Logging Wrapper
  • class library project references

Magazine wrapper

  • Log4net links
  • Contains assembly: XmlConfigAttribute

Class library project



  • Log4net links

Although you haven't posted any details in your log4net wrapper class, I am assuming that your web project does not have direct access to log4net, but through your wrapper.

As per my last answer , log4net allows configuration and constructs a logging repository in your shell project. While I'm sure there is only one repository per AppDomain , it looks like your class library project is not finding the default repository. Since it's at the AppDomain level, I doubt it is solely for your wrapper assembly directly.

Instead, it sounds like a timing issue. What happens if you call the wrapper first and then the class library? I suspect you will find that if you call your class library project first, you will not get the logger. However, if the very first registration call is for your wrapper, any subsequent requests to the registrar should work. This is because the shell project contains configuration information and the first call will set up the registration repository for the AppDomain.

While I am not a big fan of the log4net wrapper, you can fix this problem by forcing the call to your wrapper in your application startup logic, or by using your class library project using your wrapper. Keep in mind that if you are using the concept of a wrapper, your class library will not be able to use all of the log4net built-in functions (like IsDebugEnabled) and you will have to resolve these settings through your wrapper.

0


source


Log4Net.config file copied to directory on creation? You want to make sure that Log4Net.config is always Copy in properties.



I would also revise it in a separate file. I would prefer one config file over several. As you can see, it is difficult to deal with the various confiiguration files.

+1


source







All Articles