ASP.NET Core 2.1 + Log4Net

…衆ロ難τιáo~ 提交于 2020-01-04 09:02:31

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!