企业库记录器的配置
我想要将 Enterprise Library Logger 配置为写入文件,直到它达到指定的大小。
当我达到指定的大小后,我希望它执行以下操作之一:
- 滚动文件(删除旧的日志行并添加新的日志行,而不是清除整个文件)。
- 将内容保留在一个文件中并清除日志文件(仅保留一个备份文件)。
目前,我对一个文件进行了配置,每次文件已满时都会清除该文件。这是我的配置
<listeners>
<add fileName="C:\ProgramData\Hamoub\Log\TransferLog.log"
formatter="Text Formatter"
header="----------------------------------------"
rollFileExistsBehavior="Overwrite"
rollSizeKB="100000"
listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.RollingFlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
traceOutputOptions="None"
filter="All"
type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.RollingFlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
name="Rolling Flat File Trace Listener"/>
</listeners>
感谢您的帮助
I Want to configure Enterprise Library Logger to write to a file until it reaches a specified size.
After i reaches the specified size I would like it to do one of the following:
- Do roll the file (Delete old log lines and add new ones, not the clear the entire file).
- Keep the content in a file and clear the log file (keep only one backup file).
Currently I have configuration for one file that clears every time the file is full. This is my configuration
<listeners>
<add fileName="C:\ProgramData\Hamoub\Log\TransferLog.log"
formatter="Text Formatter"
header="----------------------------------------"
rollFileExistsBehavior="Overwrite"
rollSizeKB="100000"
listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.RollingFlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
traceOutputOptions="None"
filter="All"
type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.RollingFlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
name="Rolling Flat File Trace Listener"/>
</listeners>
Thanks for your help
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
因此,无法单独通过配置来做到这一点。
我的解决方案是在输出文件夹上添加 FileSystemWatcher,每当在那里创建新文件时,我都会检查是否需要删除。
我在删除之前已对文件夹文件进行了排序,因此只会删除旧文件(保留当前和以前的日志文件)。
观察者代码:
处理程序代码:
< em>希望这篇文章能够帮助那些寻找这种解决方案的人
Barak Hamou
So, There is no way to do this in configuration alone.
My solution was to add FileSystemWatcher on the output folder, and whenever a new file is created there, I checked if deletion is needed.
I have ordered the folder files before deletion so only old files will be deleted (keeping the current and previous log files.
The Watcher Code:
The handler Code:
Hopefully, this post will help someone who looks for such solution
Barak Hamou
看起来不像 Enterprise Library 4.1 滚动平面文件跟踪侦听器 有这样的配置选项。
如果您更改为
rollFileExistsBehavior="Increment"
,然后创建一个计划任务来删除除两个最新文件之外的所有文件,会怎么样?Doesn't look like the Enterprise Library 4.1 Rolling Flat File Trace Listener has such a configuration option.
What if you change to
rollFileExistsBehavior="Increment"
and then create a scheduled task that will delete all but the two most recent files?