<target xsi:type="File"
async="true"
name="jsonFileTrace"
keepFileOpen="true"
OpenFileCacheTimeout="60"
archiveAboveSize="5242880"
maxArchiveFiles="20"
maxArchiveDays="10"
archiveNumbering="DateAndSequence"
AutoFlush="false"
openFileFlushTimeout="5"
ConcurrentWrites="false"
archiveFileName="${basedir}/logs/trace/archive/${shortdate}/trace.{#}.log"
fileName="${basedir}/logs/trace/${shortdate}.log">
<layout xsi:type="JsonLayout" includeAllProperties="true">
<attribute name="time" layout="${longdate}" />
.......//other attributes
</layout>
</target>如果我如愿以偿,它可以按日期归档。但文件夹2022-09-20 不能删除,如果当前日期是2022- 10 -01,而该日期自2022-09-20已经过去了10天。

发布于 2022-09-21 15:33:11
请考虑使用此配置:
<target xsi:type="File" name="jsonFileTrace"
keepFileOpen="true"
archiveAboveSize="5242880"
autoFlush="false"
openFileFlushTimeout="5"
concurrentWrites="false"
fileName="${basedir}/logs/trace/${shortdate}/trace.${shortdate}.log">
<layout xsi:type="JsonLayout" includeAllProperties="true">
<attribute name="time" layout="${longdate}" />
.......//other attributes
</layout>
</target>并在计算机(或应用程序中)上设置一个计划好的任务,该任务每天运行,并删除超过10天的子文件夹。
https://stackoverflow.com/questions/73783383
复制相似问题