问题
I'm using log4net in ASP.NET Core 2.1 project, I don't know why I'm getting log messages duplicated, here is my log4net.config configuration
<?xml version="1.0" encoding="utf-8" ?>
<log4net>
<appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender">
<file type="log4net.Util.PatternString" value="app_data/log/%property{LogName}" />
<rollingStyle value="Date" />
<appendToFile value="true" />
<rollingStyle value="Size" />
<datePattern value="yyyyMMdd" />
<maxSizeRollBackups value="10" />
<maximumFileSize value="10000KB" />
<lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
<staticLogFileName value="true" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value=" %-5level %date{dd-mm-yyyy HH:mm:ss} %logger [%thread] - %message %exception%newline" />
</layout>
</appender>
<root>
<appender-ref ref="RollingFileAppender" />
<level value="All" />
</root>
</log4net>
here is my service where i create the log name dynamicaly
fileName = "/" + DateTime.Today.Year + "-" + ((DateTime.Today.Month.ToString().Length == 1) ? "0" : "") + DateTime.Today.Month + "-" +
((DateTime.Today.Day.ToString().Length == 1) ? "0" : "") + DateTime.Today.Day + "/"
+ society + "/" + fileName + ".log";
log4net.GlobalContext.Properties["LogName"] = fileName;
_loggerFactory.AddLog4Net(_configuration.GetValue<string>("Log4NetConfigFile:Name"));
I dont know where is the problem exactly
来源:https://stackoverflow.com/questions/51703747/asp-net-core-2-1-log4net