Search code examples
loggingweb-configlog4netconfigsection

log4net configuration exception


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" />

Solution

  • 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