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.
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".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With