Logback:文件增长超过 maxFileSize 时出现异常

Logback: Exception when the file grows beyond maxFileSize

我在 logback.xml 中有以下滚动策略。
问题是,如果文件大小超过 10 MB,就会抛出异常。 看起来它正在尝试创建一个新文件,但由于同一文件已在同一日期存在,因此无法创建并抛出异常。
例如,我们已经有一个文件 pvExport.2016-05-15.log 并且如果 pvExport.log 增长超过 10 MB,它将尝试创建与 pvExport.2016-05-[ 同名的文件=16=],因此会抛出异常,但不确定

<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <!-- rollover daily -->
            <fileNamePattern>${EXPORT_LOG_HOME}/pvExport.%d{yyyy-MM-dd}.log
                        </fileNamePattern>
            <timeBasedFileNamingAndTriggeringPolicy
                class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
                <maxFileSize>10MB</maxFileSize>
            </timeBasedFileNamingAndTriggeringPolicy>
        </rollingPolicy>

你的fileNamePattern在这种情况下实际上是无效的。来自 docs

Note the "%i" conversion token in addition to "%d". Both the %i and %d tokens are mandatory. Each time the current log file reaches maxFileSize before the current time period ends, it will be archived with an increasing index, starting at 0.

%i 转换标记添加到您的模式应该可以解决此问题:

<fileNamePattern>${EXPORT_LOG_HOME}/pvExport.%d{yyyy-MM-dd}.%i.log</fileNamePattern>