Click here to Skip to main content
15,886,567 members
Articles / All Topics

How to Solve Log4Net Config Error

Rate me:
Please Sign up or sign in to vote.
5.00/5 (2 votes)
17 Sep 2014CPOL 7.4K   4  
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 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.

log4net error

Problem Scope

My particular applications are designed as such:

log4net-concept

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.

Image 3 Image 4

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Chief Technology Officer
Bangladesh Bangladesh
I am a Software Engineer and Microsoft .NET technology enthusiast. Professionally I worked on several business domains and on diverse platforms. I love to learn and share new .net technology and my experience I gather in my engineering career. You can find me from here

Personal Site
Personal Blog
FB MS enthusiasts group
About Me

Comments and Discussions

 
-- There are no messages in this forum --