这是我的追随者:
<appender name="ApplicationRollingFile" type="log4net.Appender.RollingFileAppender">
<file type="log4net.Util.PatternString" value="logs/application.log" />
<appendToFile value="true" />
<rollingStyle value="Composite" />
<preserveLogFileNameExtension value="true"/>
<datePattern value=".yyyy-MM-dd-hhmmss" />
<maxSizeRollBackups value="50" />
<maximumFileSize value="500KB" />
<staticLogFileName value="false" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %level %logger %C.%M --- %message --- %newlineTrace:%newline %stacktrace%newline" />
</layout>
</appender>
目前输出的是:
application.time-logging-started.1.log
application.time-logging-started.2.log
application.time-logging-started.3.log
我想要的是:
application.time-of-first-rollover.log
application.time-of-second-rollover.log
application.time-of-third-rollover.log
这可以吗?如果是这样,怎么样?
答案 0 :(得分:0)
您的文件元素似乎使用PatternString作为文件名,滚动文件appender已经使用了名称转换。无需覆盖默认工作。
<appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
<lockingModel type="log4net.Appender.FileAppender+MinimalLock"/>
<file value="logs\" />
<datePattern value="yyyy-MM-dd-hhmmss'.log'" />
<staticLogFileName value="false" />
<appendToFile value="true" />
<rollingStyle value="Composite" />
<maxSizeRollBackups value="50" />
<maximumFileSize value="500KB" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline" />
</layout>
</appender>