我在整个项目中都使用了Enterprise日志,但我注意到包含日志的文件夹已经开始膨胀,不再需要旧日志了。我在app.config的背景是:
<add name="CommonListener" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.RollingFlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.RollingFlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
fileName="D:\Logs\Common.log" footer=" "
formatter="Text Formatter" header=" " rollFileExistsBehavior="Increment"
rollInterval="Midnight" rollSizeKB="1000000"/>目前,我能够手动删除这些文件,但这将导致问题的发生,因为我将无法访问它们的存储位置。是否有一个配置,我可以添加到配置文件,将标志他们删除后,'x‘的天数?
发布于 2014-04-30 10:43:17
我通过在监听器声明中将以下内容添加到app.config来限制企业日志记录所需的文件数量,从而解决了这一问题:
maxArchivedFiles="20"现在,日志记录将只保留20个文件,并在达到此阈值时删除最老的文件。
我发现的另一种不涉及企业库的方法是:Background Worker Check For When It's Midnight?
这是通过System.IO完成的,以便在某段时间过去时引发事件。然后,将它与一个函数结合起来,以删除在这个答案中找到的所有文件:
https://stackoverflow.com/questions/23364679
复制相似问题