How log4net does not clear the log every time XmlConfigurator.Configure () is called in the process

In my application, I include 3 libraries:

Log4net Common.Logging.log4net Quartz (use Common.Logging.log4net to write logs) 

This is my log4net partition configuration:

 <log4net> <root> <level value="ALL" /> <appender-ref ref="FileAppender" /> </root> <appender name="FileAppender" type="log4net.Appender.FileAppender"> <file value="quartz.log" /> <appendToFile value="false" /> <layout type="log4net.Layout.PatternLayout"> <conversionPattern value="%date [%thread] %level %logger - %message%newline" /> </layout> </appender> </log4net> 

Everything is fine, but the problem is with XmlConfigurator.Configure (). This command is called 2 times in order:

  • Called when the application starts β†’ I am recording a log.
  • Called when quartz starts. (I checked when to read the source code for Common.Logging.log4net) β†’ Quartz logging.

After the start of quartz, my logs were cleared due to XmlConfigurator.Configure (). This means that when this command is called, the log will be cleared. I do not want my log to be cleared after this command with a name in the process .

I can get the source dll Common.Logging.log4net to modify the code to check if log4net is really configured and call XmlConfigurator.Configure () if not. But I do not like it.

Please help me find another solution without changes in the DLL.

Additional information: http://neilkilbride.blogspot.com/2008/04/configure-log4net-only-once.html

+4
source share
1 answer

You configured that the prefix file creates a new log file when reconfiguring log4net:

  <appendToFile value="false" /> 

Change this to:

  <appendToFile value="true" /> 

Log messages will be added at the end of the file, even if you call XmlConfigurator.Configure() several times.

+2
source

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


All Articles