使用 log4net 重写日志中的数据

Rewriting data in logs with log4net

这是我的logger.config

 <?xml version="1.0"?>
    <logger>
      <path>C:\</path>
      <file>dd-MM-yyyy'.log'</file>
      <levels>
        <add>ERROR</add>
        <add>INFO</add>
      </levels>
      <pattern>{level}|{date}|{method_guid}|{method_name}|{description}|{status}|{msg}|{inout}|{param0}</pattern>
      <dateFormat>MM/dd/yy H:mm:ss.fff</dateFormat>
      <reloadEveryMinutes>1</reloadEveryMinutes>
      <appendToFile value="true" />
      <maxSize>1MB</maxSize>
    </logger>

这里我设置了记录器的添加设置。 var hierarchy = (Hierarchy)LogManager.GetRepository(); hierarchy.Configured = 假;

        hierarchy.Root.RemoveAllAppenders();

        var patternLayout = new PatternLayout() { ConversionPattern = "%m%n" }; //%m - message, %n - new line
        patternLayout.ActivateOptions();

        var roller = new RollingFileAppender
        {
            AppendToFile = true,
            StaticLogFileName = false,
            File = config.Path,
            DatePattern = config.FileName,
            PreserveLogFileNameExtension = true,
            Layout = patternLayout,
            MaxSizeRollBackups = 10000,
            MaximumFileSize = "10000",
            RollingStyle = RollingFileAppender.RollingMode.Composite,
            CountDirection = 0

        };
        roller.ActivateOptions();
        hierarchy.Root.AddAppender(roller);

        hierarchy.Root.Level = Level.All;
        hierarchy.Configured = true;

并且 log4net 生成名称为 15-05-2017 的文件。当文件大小超过 1MB 时,它会创建新文件 15-05-2017.1 并将旧数据放入其中并将新数据写入 15-05-2017.

15-05-2017.1写入新数据怎么办?

我认为您需要根据文档将 CountDirection 更改为 -1(这是默认值), 见 CountDirection