RollingFileAppender,滚动后不再追加

发布于 2024-09-18 01:22:24 字数 744 浏览 1 评论 0原文

我有一个滚动文件附加器,每天晚上它都会滚动文件。然而,当它滚动时,新文件只有一个日志条目。该文件似乎不再附加日志条目。如果我重新启动该服务,它会正确记录。

这是我的设置:

<appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
  <file value="Log.txt"/>
  <appendToFile value="true" />
    <staticLogFileName value="true" />
  <rollingStyle value="Date" />
  <datePattern value=" yyyy-MM-dd" />
  <lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
  <threshold value="DEBUG" />
  <layout type="log4net.Layout.PatternLayout">
   <conversionPattern value="%date [%thread] %-5level %logger  - %message%newline" />
  </layout>
 </appender>

I have a rolling file appender and every night it rolls the file. However, when it rolls it, the new file only has one log entry. It seems that file is not appending log entries anymore. If I restart the service it logs correctly.

Here are my settings:

<appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
  <file value="Log.txt"/>
  <appendToFile value="true" />
    <staticLogFileName value="true" />
  <rollingStyle value="Date" />
  <datePattern value=" yyyy-MM-dd" />
  <lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
  <threshold value="DEBUG" />
  <layout type="log4net.Layout.PatternLayout">
   <conversionPattern value="%date [%thread] %-5level %logger  - %message%newline" />
  </layout>
 </appender>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

我三岁 2024-09-25 01:22:26

将 maxSizeRollBackups 设置为一个值(将 maxSizeRollBackups 设置为负 1 以允许无限数量的备份文件)

这个例子展示了如何配置
RollingFileAppender 滚动日志文件
每次程序执行一次。这
appendToFile 属性设置为 false
以防止附加程序
覆盖现有文件。这
maxSizeRollBackups 设置为负数
1 允许无限多个
备份文件。文件大小确实有
受到限制,但这里设置为 50
如果日志文件超过千兆字节
单次运行期间的大小限制
然后它也会被滚动。

<appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
    <file value="logfile.txt" />
    <appendToFile value="false" />
    <rollingStyle value="Size" />
    <maxSizeRollBackups value="-1" />
    <maximumFileSize value="50GB" />
    <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline" />
    </layout>
</appender>

参考

Set maxSizeRollBackups to a value perhaps (maxSizeRollBackups set to negative 1 to allow an infinite number of backup files)

This example show how to configure the
RollingFileAppender to roll log files
once per program execution. The
appendToFile property is set to false
to prevent the appender from
overwriting the existing files. The
maxSizeRollBackups is set to negative
1 to allow an infinite number of
backup files. The file size does have
to be limited but here it is set to 50
Gigabytes which, if a log file exceeds
this size limit during a single run
then it will also be rolled.

<appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
    <file value="logfile.txt" />
    <appendToFile value="false" />
    <rollingStyle value="Size" />
    <maxSizeRollBackups value="-1" />
    <maximumFileSize value="50GB" />
    <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline" />
    </layout>
</appender>

Ref.

南风几经秋 2024-09-25 01:22:25

我发现问题是什么了。我在配置中删除了这一行,并在滚动文件后开始正确附加:

<lockingModel type="log4net.Appender.FileAppender+MinimalLock" /> 

I found what the issue was. I removed this line in the configuration and it started to append correctly after it rolled the file:

<lockingModel type="log4net.Appender.FileAppender+MinimalLock" /> 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文