Log4Net Not Logging In File

Some time back I was working on a console application that required extensive logging for actions at various stages of the workflow. I have been using Log4Net for logging in all our applications for quite a long time. So Log4Net is the logger of choice for this application as well. One thing I noticed that after a recent change, logger stopped working. I am using a FileAppender to log messages in a file. When I say it stopped working, it means is that Log4Net was not writing any messages in log file.

I checked at all the settings in app.config file for Log4Net entries. The settings were still pointing to write to same file it was writing before and in the same folder. After debugging for some time, I could not reach any resolution. It was definitely something to do with Log4Net itself. One thing that makes it little harder with Log4Net is that it does not throw any errors or exception when something is not working as expected. It is not a drawback of this framework. This is how one will expect a logging framework to work that it should not become a bottleneck in itself for stability of any application. Best thing about Log4Net is that it provides plenty of settings to look inside its inner workflow and errors at run time.

        <log4net debug="true">...</log4net>

A very useful setting for Log4Net is debug attribute at the very root level log4net node in configuration file. By default this setting is set to false. When this setting is turned on, it starts spitting internal error message including any exceptions that are thrown in console output itself. After I had set this setting, I saw the following exception in output window.

    log4net:ERROR Failed to parse config file. Is the <configSections> specified as: <section name="log4net" 
type="log4net.Config.Log4NetConfigurationSectionHandler,log4net, Version=1.2.13.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a" />
System.Configuration.ConfigurationErrorsException: An error occurred creating the configuration section handler for log4net: 
    Could not load file or assembly 'log4net, Version=1.2.13.0, Culture=neutral, PublicKeyToken=1b44e1d426115821' or one of its dependencies. 
The located assembly's manifest definition does not match the assembly reference. 
...
   --- End of inner exception stack trace ---

As you can see from the message that it is loud and clear that Log4Net assembly has some version matching issues. After I fixed the version in configuration file, logger started working as expected. So when you run into some unexpected issues with Log4Net, first thing to try is make use of debugging switches available in Log4Net to get some more details before digging into your own code.

Search

Social

Weather

9.5 °C / 49.2 °F

weather conditions Clear

Monthly Posts

Blog Tags