Background
While using log4net for logging and using a separate configuration file, I encountered a strange error that log4net can't locate the configuration file, even though file and configurations are already there. This problem drives me nuts and finally I found few solutions to fix the problem.
Problem Scope
My particular applications are designed as such:
So as shown in the diagram, several type of app types will hookup with Log4Net wrapper to get logging facility and all logging related logic is 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 are few problems and a few solutions. The solution can vary 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 to look for XmlConfigurator.Configure();
. This line is responsible for initiating the log4net. This configuration should exist in a single place where logging actually happen, not client apps.
One of these 2 or both tricks should help to solve this problem.
CodeProject