Best practices for creating a logger library using log4net. Is
Posted
by
VolleyBall Player
on Stack Overflow
See other posts from Stack Overflow
or by VolleyBall Player
Published on 2012-05-31T02:34:04Z
Indexed on
2012/06/07
4:40 UTC
Read the original article
Hit count: 190
My goal is to create a log4net library that can be shared across multiple projects.
In my solution which is in .net 4.0, I created a class library called Logger and referenced it from web project.
Now I created a logger.config in the class library and put all the configuration in the logger.config file. I then used
[assembly: log4net.Config.XmlConfigurator(Watch = true, ConfigFile = "Logger.config")]
When I run the web app nothing is getting logged. So I added this line of code in web.config
<add key="log4net.Internal.Debug" value="true"/>
which gave me debugging info and error information
Failed to find configuration section 'log4net' in the application's .config file. Check your .config file for the and elements. The configuration section should look like:
I moved the configuration from logger.config to web.config and everything seems to work fine.
I don't want the log4net configuration in web.config but have it logger.config as a cleaner approach. The goal is to make other projects use this library and not have to worry about configuration in every project.
Now the question is, How do I do this? What am I doing wrong? Any suggestion with code example will be beneficial to everyone.
FYI, I am using structure map IOC to reslove the logger before logging to it.
© Stack Overflow or respective owner