How to solve Log4Net Config Error

Background

While using log4net for logging and using a separate configuration file I encountered a strange error that log4net cant locate the configuration file, even though file and configurations are already there. This problem drive me nuts and finally i found few solutions to fix the problem.

log4net error

Problem Scope

My particular applications is designed as such

log4net-concept

So as shown in diagram, several type of app type will hookup with Log4Net wrapper to get logging facility and all logging related logic’s are implemented on Log4Net wrapper. As the problem states every time a client app is trying to invoke log4net wrapper it gets xml configuration error “Check your .config file for the <log4net> and <configSections>….”

Solution

There is few problem and few solution, Solution can very on context.

On the client project , select Log4Net config file and set this file to Build Action of Content with Copy to Output Directory of Copy Always.

Another alternative is look for  XmlConfigurator.Configure();. This line is responsible for initiating the log4net. This configuration should exist a single place where logging actually happen, not client app’s.

One of these 2 or both tricks should help to solve this problem.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s