Click here to Skip to main content
13,093,097 members (69,584 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


Posted 28 Jul 2011

Finding log4net hidden exceptions....

, 28 Jul 2011
Rate this:
Please Sign up or sign in to vote.
Finding log4net hidden exceptions....

Recently I worked on a project that was mainly a couple of Web Services, and included a couple of more C# class libraries (e.g.: a Data Access Layer, Common project with general utilities, etc.).

In the web services code, we had a lot of calls to our logging utility, which in this case used log4net. I had previous experience using log4net, so I knew (or thought I knew!) how to set it up quickly. I added what I needed in the web.config file, and thought it was enough.

Once I started testing the web services out, I realized that something was wrong with the log4net configuration. The problem was that it wasn't writing anything to any log file whatsoever. The bigger problem was that we didn't know why!?!...
log4net doesn't throw any exceptions if it doesn't work, and this way it doesn't interfere with your running application if, let's say, the log file it should write to has been deleted or is locked by another application for some reason...

However, log4net will write to a trace file, if you set one up...
This led me to the solution of my problem. All I did, was add a TextWriterTraceListener in my web.config, without even altering any code, and the log4net error was immediately written to my trace file.

In my case, I forgot to tell log4net to use XML configuration, but this is irrelevant. The point is that this might help you find out what your error is in the case of misconfiguration with log4net...

To set up a trace file through log4net, just add:

        <trace enabled="true" 

        autoflush="false" indentsize="4">
                <add name="myListener" 


                <remove name="Default">

to your web.config file.

Trace listeners are a powerful tool when used wisely. :)
You can read more about them here: MSDN - Trace Listeners.

Happy tracing...


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


About the Author

Gilly Barr
Web Developer
Israel Israel
Started programming e-commerce sites with PHP & MySQL at the age of 14. Worked for me well for about 5 years.

Transfered to C# &, while serving in the IDF.
Worked on the 'Core Performance' Team at (Sears Israel)
Currently working at

Check out my blog!
or my twitter

You may also be interested in...

Comments and Discussions

-- There are no messages in this forum --
Permalink | Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.170813.1 | Last Updated 28 Jul 2011
Article Copyright 2011 by Gilly Barr
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid