Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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" />
like image 888
ram Avatar asked Dec 18 '09 19:12

ram


People also ask

Where is log4net configuration file?

You can configure the log4net. config file to create log files. The file is located in the webroot\App_data directory of the installation.

Does log4net work with .NET 5?

log4net is one of three very popular frameworks for implementing log messages in your application (Serilog and NLog being the other two). log4net works with almost any version of . NET (including . NET Core).

Is log4net dependent on log4j?

Log4net is a logging utility for . NET applications. It's based on log4j, which is for Java applications. Log4net is highly configurable, so you can use it in many scenarios.


1 Answers

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

like image 101
Mauricio Scheffer Avatar answered Oct 01 '22 00:10

Mauricio Scheffer