c# - Enterprise Library Logging 5 - 滚动平面文件

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

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

这是来自 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

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

最佳答案

像这样将文件名作为时间戳怎么样:exception.2011-12-22.log

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

只是一个想法...

关于c# - Enterprise Library Logging 5 - 滚动平面文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8607835/

相关文章:

c# - 将图像复制并重命名到 Windows 8 应用程序上的文件夹

azure-sql-database - SQL Azure transient 故障与数据访问应用程序 block 6.0

c# - 无法解析符号 'EnterpriseLibraryContainer'

c# - Microsoft Enterprise Library - 缓存机制到期

c# - MySQL 6 与 Enterprise Library Data 5 的连接

c# - TPL Dataflow,仅在所有源数据 block 完成时保证完成

c# - 尝试添加一对多关系时出现 NullReferenceException

c# - 在 MS 企业库或 Log4net 等 3rd 方组件上创建包装器是一个好习惯吗?

Azure 缓存 - Microsoft Enterprise Library 5.0 在 Azure 上缓存应用程序 block 如何?

C# - 将列表转储到下拉列表