尝试不每秒创建新文件,但是如果文件限制超出限制,则使用log4net创建新文件 [英] Trying not to create new file every second but if file limit exceed then create new file using log4net

查看:51
本文介绍了尝试不每秒创建新文件,但是如果文件限制超出限制,则使用log4net创建新文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建命名约定为 Service_HH_mm_ss.txt 的文件.

I am trying to create file with naming convention as Service_HH_mm_ss.txt.

文件命名格式为

<文件类型="log4net.Util.PatternString" value ="C:\\ Log \\%date {yyyy-MM-dd} \\ Service_%date {HH_mm_ss} .log"/>

我也将文件的最大大小指定为

Also i have given file max size to

<rollingStyle value="Size" />      
<maximumFileSize value="10KB" />

仅当大小超过10KB时,我才想创建新文件,但是每一秒钟都在创建新文件.

无法找到解决方案.

配置文件代码为:
< file type ="log4net.Util.PatternString" value ="C:\\ Log \\%date {yyyy-MM-dd} \\ Service_%date {HH_mm_ss} .log"/>
< encoding value ="utf-8"/>< appendToFile value ="true"/><rollingStyle value="Size"/>< maxSizeRollBackups value ="20"/>< maximumFileSize value ="10KB"/>< staticLogFileName value ="false"/>< layout type ="log4net.Layout.PatternLayout">< conversionPattern value =%date%level-%message%n"/></layout>

有可能做我想做的事,我没有得到任何解决办法.

Is it possible to do what i want, i ma not getting any solution.

推荐答案

在Appender定义中,文件名"的值每秒更改一次.因此log4net每秒创建一个新文件.如果需要确切的时间作为文件名的一部分,则可以使用滚动样式'Composite'并添加DatePattern,如下所示:

In your Appender definition the value for the File name changes every second. Therefor log4net creates a new file every second. If you need the exact time to be part of the file name, you can use rolling Style 'Composite' and add a DatePattern like so:

<appender name="FileAppender" type="log4net.Appender.RollingFileAppender">
<file type="log4net.Util.PatternString" value="C:\\Log\\%date{yyyy-MM-dd}\\Service_" />

  <encoding value="utf-8" />
  <appendToFile value="true" />
  <rollingStyle value="Composite" />
  <datePattern value = "HH_mm_ss'.log'"
  <maxSizeRollBackups value="20" />
  <maximumFileSize value="10KB" />
  <staticLogFileName value="false" />
  <layout type="log4net.Layout.PatternLayout">
     <conversionPattern value="%date %level - %message%n" />
  </layout>

这篇关于尝试不每秒创建新文件,但是如果文件限制超出限制,则使用log4net创建新文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆