Log4net duplicates records when only one (root) logger is used

My log4net configuration looks like this:

<log4net> <appender name="CloudWatchLogsAppender" type="CloudWatchAppender.CloudWatchLogsAppender, CloudWatchAppender"> <layout type="log4net.Layout.PatternLayout"> <conversionPattern value="%date [%thread] %level %logger.%method - %message%newline" /> </layout> <groupName value="agroupname" /> <streamName value="astreamname" /> </appender> <root> <level value="INFO" /> <appender-ref ref="CloudWatchLogsAppender" /> </root> <logger name="Amazon"> <level value="OFF" /> </logger> </log4net> 

In classes, I create a registrar with

 private static readonly ILog Log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 

and call Log.Error (message); only once, but in my logs all errors are duplicated. In addition, this method is called in the controller class for the WebApi project.

I read in other questions that this can happen when using multiple registrars and distributing them to the root registrar, however I only use the root registrar in this instance.

+5
source share
1 answer

It seems that the problem was the specific configuration of the AWS SDK:

  <add key="AWSLogging" value="log4net" /> 

Somehow, this duplicates the applications and causes duplicate messages.

To fix, simply remove this parameter or change the value to "none".

+5
source

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


All Articles