【问题标题】:Enterprise Library Logging 5 - Rolling Flat FilesEnterprise Library Logging 5 - 滚动平面文件
【发布时间】:2012-01-26 07:52:46
【问题描述】:

有没有办法始终将时间戳模式应用于我当前的日志文件?

这是我在 app.config 中的日志文件监听器示例

<add name="Exception" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.RollingFlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.RollingFlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
fileName="%APPDATA%\MyProgram\Logs\exception.log" formatter="PrismText"
rollFileExistsBehavior="Increment" rollInterval="Day" timeStampPattern="yyyy-MM-dd" rollSizeKB="3000"
maxArchivedFiles="10" />

现在,一旦我达到最大大小或日期更改,它会重命名日志,但有没有办法让初始日志文件显示时间戳模式?

我在我的日志文件夹中得到了这个:

exception.log <-- Current log
exception.2011-12-22.1.log
exception.2011.12.22.2.log

我想要这个:

exception.2011-12-22.log (or exception.2011-12-22.1.log) <-- Current Log
exception.2011.12.22.2.log

这没什么大不了的,因为我可以查看修改/创建的日期,但如果能快速修复它会很好。

【问题讨论】:

  • 我不认为这是 100% 可能的。我确实看到了一个带有环境变量的 Kludge,它涉及每天的应用重启。如果您真的非常想要该功能,您可以创建自己的 RollingFlatFileTraceListener 版本,以这种方式工作。
  • 我也没有找到解决方案,我要自己解决。

标签: c# enterprise-library enterprise-library-5


【解决方案1】:

如何将文件名作为时间戳提供如下:exception.2011-12-22.log

您可以通过 fluent api 执行此操作,或者如果您不想从代码中使用它,您可以每天更改配置文件。如果配置文件更改,日志记录块会自动更改配置。但这当然会让你的代码有点复杂。

只是一个想法......

【讨论】:

    猜你喜欢
    • 2014-06-15
    • 2011-11-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多