views:

1222

answers:

1

I am using log4net for logging. My logging configuration is stored in a separate file.

Web.Config:ConfigSections

<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net" />

Specifying my config file in AssemblyInfo.cs

[assembly: log4net.Config.XmlConfigurator(ConfigFile="Log4Net.config", Watch = true)]

And when I initialize my LogManager, I get this error

"System.TypeLoadException"
message: Could not load type 'log4net.Config.Log4NetConfigurationSectionHlandler' from assembly 'Log4net'.

Yes it says "Log4NetConfigurationSectionHlandler'", it is not a typo

and later, this error

An error occurred creating the configuration section handler for log4net: Could not load type 'log4net.Config.Log4NetConfigurationSectionHlandler' from assembly 'Log4net'.

Edit: Tried Mauricio Scheffer's suggestion

got

log4net:ERROR XmlConfigurator: Failed to find configuration section 'log4net' in the application's .config file. Check your .config file for the <log4net> and <configSections> elements. The configuration section should look like: <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net" />
+4  A: 

If you have your config in a separate log4net.config file you don't need the sectionHandler. Remove it.

You're also probably calling XmlConfigurator.Configure() somewhere in your code. Remove that as well.

Also see this question

Mauricio Scheffer
I second this response. I was getting the same problem in my WPF application when I had the log4net section in my `app.config` file. I moved the config to a separate log4net.config file and it resolved the issue.
Rob Sobers
I got this error on trying this suggestion:log4net:ERROR XmlConfigurator: Failed to find configuration section 'log4net' in the application's .config file. Check your .config file for the <log4net> and <configSections> elements. The configuration section should look like: <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net" />
ram
@ram: you're probably calling XmlConfigurator.Configure() somewhere in your code. remove that.
Mauricio Scheffer
I am a bit lost mauricio, I am calling it when I initialize my Log Managerstatic ActivityLogManager() { log4net.Config.XmlConfigurator.Configure(); }It should not be called ?
ram
OK now I get it, since my config file is external, I should not call XMLConfigurator.Configure as it is looking for the config section in my web/app.config. Is my understanding correct ?
ram
Exactly, you should *not* call it. The assembly attribute already handles the initialization.
Mauricio Scheffer
Hey Mauricio, should the external config file be ".xml" or can it have ".config" extension ?
ram
@ram doesn't matter, it can be anything.
Mauricio Scheffer
Thanks Mauricio. Am working on it, will update this post ASAP
ram
Thanks Mauricio it worked. Am posting one new question soon. Its about using one class in am assembly to log all events and I see that "logger" is getting set to this static logging class and not the class which is calling this Log methods
ram