Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Log4net duplicate entries 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 instantiate the logger with

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

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

I've read in other questions that it can happen when using multiple loggers and them propagating messages upto the root logger, however, I am only using the root logger in this instance.

like image 384
Adam Nygate Avatar asked Dec 08 '16 17:12

Adam Nygate


1 Answers

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

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

Somehow, this duplicated the appenders and caused the double messages.

To fix, just remove this setting or change the value to "none".

like image 97
Adam Nygate Avatar answered Nov 06 '22 04:11

Adam Nygate