When is Log4Net configured?

Given what you have

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

in the AssemblyInfo.cs file when is Log4Net configured? Is this when you start the application or when you use the recorder for the first time?

+6
source share
2 answers

The configuration file is used when you call the LoggerManager class LoggerManager . This is usually caused by a call to LogManager.GetLogger.

See http://logging.apache.org/log4net/release/sdk/log4net.Config.XmlConfiguratorAttribute.html for more details; in particular note:

Log4net will only search the assembly once. When using the assembly level of log4net attributes to control the configuration of log4net, you must ensure that the first call to any of the LoggerManager methods is made from the assembly with configuration attributes.

+7
source

Quote from the Apache log4net site:

Therefore, if you use configuration attributes, you must call log4net so that it can read the attributes. A simple call to LogManager.GetLogger will read and process the attributes on the calling assembly. Therefore, it is imperative to make a registration call as early as possible during the launch of the application and, of course, before any external assemblies are downloaded and activated. http://logging.apache.org/log4net/release/manual/configuration.html

Here is a good article on how to configure the configuration and run it correctly: http://www.fooji.net/blog/post/2010/04/27/logging-log4net-e28093-part-iii.aspx

Basically, you need to either make a registration call (which configures log4net if it is not already configured) or use the DOMConfigurator to manually configure log4net.

+3
source

Source: https://habr.com/ru/post/887361/


All Articles