具有日志文件管理(滚动)的.Net WCF服务跟踪日志 [英] .Net WCF Service Trace Log with log file management (Rolling)

查看:89
本文介绍了具有日志文件管理(滚动)的.Net WCF服务跟踪日志的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些.Net WCF服务,对于这些服务,我已经将app.config文件配置为将发送和接收的消息记录在.svclog文件中,该文件可由服务跟踪查看器工具"(SvcTraceViewer.exe)读取.该工具可以很好地呈现日志文件,清楚地显示正在处理的SOAP消息.

I have some .Net WCF services, for these services I have configured the app.config file to log the messages sent and received in a .svclog file which is readable by "Service Trace Viewer Tool" (SvcTraceViewer.exe) . This tool renders the log files nicely clearly showing the SOAP messages being processed.

我必须使用System.Diagnostics.XmlWriterTraceListener侦听器来正确设置.svclog文件的格式,以便可由服务跟踪查看器工具进行处理.

I have to use the System.Diagnostics.XmlWriterTraceListener listener to correctly format the .svclog file to be processable by the Service Trace Viewer Tool.

我遇到的问题是.svclog文件变得太大&服务跟踪查看器工具由于响应时间慢而变得无法使用.

The problem I have is that the .svclog file becomes too large & the Service Trace Viewer Tool becomes unusable due to slow response times.

Service Trace Viewer Tool确实提供了一种工具,如果文件大小> 40MB,则允许打开该日志文件的一部分,但这仍然太慢. app.config文件中似乎没有任何工具可以配置.svclog使其每天或当文件达到特定大小时自动创建一个新文件.

The Service Trace Viewer Tool does provide a facility to allow a portion of the log file to be opened if the file is > 40MB in size, but this is still too slow. There appears to be no facility in the app.config file to configure the .svclog to automatically create a new file each day or when the file gets to a certain size.

有一个名为Microsoft.VisualBasic.Logging.FileLogTraceListener的文本日志侦听器,它确实支持logfilecreationschedule ="Daily"属性,该属性每天都会滚动日志文件,但是操作支持人员很难从此侦听器中获得生成的日志文件不能使用,因为日志条目无法很好地呈现,并且大型xml文档加剧了混乱.

There is a text log listener called Microsoft.VisualBasic.Logging.FileLogTraceListener which does support a logfilecreationschedule="Daily" property which rolls the log file daily, however the resulting log file from this listener is difficult for an operation support person to use as the log entries are not well rendered and the large xml docs contribute to the confusion.

在该领域的最佳实践是什么,看来我可能不得不编写一个自定义WCF日志扩展名,似乎只是为了解决内置System.Diagnostics.XmlWriterTraceListener中缺少日志文件滚动功能的问题,日志侦听器/附加器.

What is the best practice in this area, it looks like I may have to write a custom WCF log extension which seems like overkill just to deal with a lack of a log file roll feature in the built in System.Diagnostics.XmlWriterTraceListener log listener / appender.

我还尝试了一个脚本来停止我的应用程序并重命名日志文件,但这似乎是不可能的,因为在Windows上,handle.exe和openfile实用程序无法关闭通过网络共享打开的文件,因此我可以如果有人通过网络共享来浏览旧日志文件,则不要重命名/移动旧日志文件.不久将对此发布一个单独的问题.

I also experimented with a script to stop my application and rename the log files but this does not seem to be possible because on Windows the handle.exe and openfile utilities are unable to close a file opened over a network share so I can't rename / move the old log file if someone is browsing it over a network share. Will post a separate question about that shortly.

谢谢, 马特.

推荐答案

您可以开发自己,也可以使用已经存在的专用XmlWriterTraceListener,也可以使用循环跟踪日志机制.

You can either develop yourself or use an already existing specialized XmlWriterTraceListener or use a circular tracing log mechanism.

XmlWriterTraceListener有一个专门的实现,可以在Codeproject上执行滚动日志跟踪:

There is a specialized implementation of the XmlWriterTraceListener that performs rolling log tracing on Codeproject:

http://www.codeproject.com/Articles/30956/A- Rolling-XmlWriterTraceListener

使用循环跟踪时,您有两个文件,每个文件最多可以存储所需跟踪日志数据总数的一半.侦听器创建一个文件并写入该文件,直到达到数据大小一半的限制为止,此时它将切换到第二个文件.当侦听器达到第二个文件的限制时,它将使用新的跟踪覆盖第一个文件.

With circular tracing you have two files that can each store up to half of the total desired trace log data. The listener creates one file and writes to that file until it reaches the limit of half of the data size, at which point it switches to a second file. When the listener reaches the limit for the second file - it overwrites the first file with new traces.

http://msdn.microsoft.com/en-us/library/aa395205.aspx

这篇关于具有日志文件管理(滚动)的.Net WCF服务跟踪日志的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆