找不到 属性 [rollingStyle] 以在 [log4net.Appender.FileAppender] 上设置对象

Cannot Find Property [rollingStyle] to set object on [log4net.Appender.FileAppender]

我有一个配置了 log4net 的 app.config 文件。但是我的文件没有被创建。在记录器内部,它显示错误。

 <configSections>
    <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net" />
  </configSections>
  <log4net>
    <logger name="ApplicationLogger">
      <appender-ref ref="XmlAppender" />
      <level value="ALL" />
    </logger>
    <appender name="XmlAppender" type="log4net.Appender.FileAppender">
      <file type="log4net.Util.PatternString" value="C:\MyApplication\Logs\%property{LogName}.log" />
      <appendToFile value="true" />
      <rollingStyle value="Composite" />
      <datePattern value=".yyyyMMdd-HHmm" />
      <maxSizeRollBackups value="10000" />
      <maximumFileSize value="1MB" />
      <countDirection value="1"/>
      <immediateFlush value="true" />
      <appendToFile value="true" />
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%message%n" />
      </layout>
    </appender>
</log4net>

我的C#代码如下:

public void LogMsg(string msg)
{
    try
    {
        strLogFileName = GetFileName();
        log4net.Repository.ILoggerRepository loggerRepository =         
        LogManager.CreateRepository(strLogFileName + "Repository");
        ThreadContext.Properties["LogName"] = strLogFileName;
        log4net.Config.XmlConfigurator.Configure(loggerRepository);
    }
    catch (Exception ex) { }
    logger = LogManager.GetLogger(strLogFileNameECU + "Repository", "ApplicationLogger");
    logger.Error(msg);
}

请告诉我哪里做错了。

对于滚动文件,你应该使用log4net.Appender.RollingFileAppender,这里是一个配置演示

<appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender">
    <file value="log/log" />
    <appendToFile value="true" />
    <rollingStyle value="Date" />
    <datePattern value="_yyyy-MM-dd.\t\x\t" />
    <maxSizeRollBackups value="10" />
    <maximumFileSize value="1MB" />
    <staticLogFileName value="false"/>
    <layout type="log4net.Layout.PatternLayout">
      <conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline" />
    </layout>
  </appender>