具有静态文件扩展名的 Log4Net 复合 RollingFileAppender

发布于 2024-10-31 07:17:11 字数 823 浏览 3 评论 0原文

当前版本的 Log4net 是否有办法创建具有复合滚动样式的 RollingFileAppender,其中滚动文件始终保留给定的扩展名(在我的情况下为 .log)?

我想要的格式示例:

MyLog.log
MyLog.2011-04-10.1.log
MyLog.2011-04-10.2.log
MyLog.2011-04-10.3.log

我发现 这篇文章 上面写着有一个“PreserveLogFileNameExtension”属性,但它不包含在官方二进制文件中。现在还是这样吗?

如果是这样:谁能解释为什么这个属性仍然不是 Log4Net 的官方部分?我对使用自定义构建有点怀疑,但也许我不应该这样?

我也很好奇为什么默认功能不保留文件扩展名。我不明白为什么它会让用户知道所有日志文件都有不同的扩展名。

编辑:通过这样做让它工作:
1:下载并构建log4net源代码
2:应用这些补丁: https://issues.apache.org/jira/browse/ LOG4NET-64
3:在配置中将 PreserveLogFileNameExtension 设置为“true”。

Does the current version of Log4net have a way to create a RollingFileAppender with composite rolling style where the rolled files always preserves the given extension (.log in my case)?

Example of the format I would like:

MyLog.log
MyLog.2011-04-10.1.log
MyLog.2011-04-10.2.log
MyLog.2011-04-10.3.log

I found this post which says that there is a "PreserveLogFileNameExtension" property, but that it's not included in the official binaries. Is this still the case?

If so: Can anyone explain why this property is still not an offical part of Log4Net? I am a bit sceptical to use a custom build, but maybe I should not be?

I am also curious to know why the default functionality does not preserve the file extension. I do not see why it would gain the user that all the log files have different extensions.

Edit: Got it working by doing this:
1: Downloading and building the log4net source code
2: Applying these patches: https://issues.apache.org/jira/browse/LOG4NET-64
3: Setting PreserveLogFileNameExtension to "true" in the config.

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

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

发布评论

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

评论(3

几味少女 2024-11-07 07:17:11

您尝试过这些参数吗?

<file value="log-files\MyLog" />
<appendToFile value="true" />
<rollingStyle value="Date" />
<datePattern value="yyyy-MM-dd'.log'" />
<param name="StaticLogFileName" value="false" />

它将保留扩展名,但会在每个文件名中为您提供一个日期,如下所示。

MyLog2011-05-16.log 
MyLog2011-05-17.log 
MyLog2011-05-18.log 
MyLog2011-05-19.log 

也许可以将其与尺寸滚动结合起来?

Have you tried these parameters?

<file value="log-files\MyLog" />
<appendToFile value="true" />
<rollingStyle value="Date" />
<datePattern value="yyyy-MM-dd'.log'" />
<param name="StaticLogFileName" value="false" />

It will preserve the extension, but will give you a date in every filename like this.

MyLog2011-05-16.log 
MyLog2011-05-17.log 
MyLog2011-05-18.log 
MyLog2011-05-19.log 

Maybe it is possible to combine this with the size rolling?

在你怀里撒娇 2024-11-07 07:17:11

情况没有改变。 log4net 没有更新版本。我不清楚何时(是否)会有新版本......

我认为您不需要太担心使用自定义构建。测试你的软件,如果它能工作那就足够好了。

编辑:有一个新版本应包含 LOG4NET-64。当然,您仍然可以坚持您的自定义构建。

The situation is unchanged. There is no newer release of log4net. It is quite unclear to me when (if) there will be a new release...

I think you do not need to worry to much about using a custom build. Test your software, if it works it is good enough.

EDIT: There is a new release that should include LOG4NET-64. Of course you can still stick to your custom build.

猥琐帝 2024-11-07 07:17:11

我正在使用此配置:

<file value="" />
<appendToFile value="true" />
<rollingStyle value="Date" />
<datePattern value="yyyyMMdd'.log'" />
<staticLogFileName value="false" />

要获取如下文件名:

  • 20111101.log
  • 20111102.log
  • 20111103.log

I'm using this configuration:

<file value="" />
<appendToFile value="true" />
<rollingStyle value="Date" />
<datePattern value="yyyyMMdd'.log'" />
<staticLogFileName value="false" />

To get filenames like:

  • 20111101.log
  • 20111102.log
  • 20111103.log
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文