自定义 TraceListener Windows 应用程序
到目前为止,在我的应用程序中,我将所有跟踪事件记录到硬盘驱动器上的文件中。
我现在想以单独的 Windows 跟踪应用程序的形式增强它,该应用程序侦听
来自主应用程序的跟踪(当它们生成时)并在
类似 gridview 的界面上报告它。现在的问题是:
我必须使用哪种 TraceListener 才能在读取日志信息的速度方面获得最大收益?
限制 由于某些限制,我无法使用数据库日志记录和读取方法,
监听应用程序 eventLogs 有什么帮助吗?
感谢您的建议和时间。
So far in my application i am logging all the trace events to a file on my hard drive.
I now want to enhance it in the form of a separate windows trace application which listens
to the trace from the Main application (as they are generated) and report it on a
gridview like interface. Now the question is :
What kind of TraceListener i have to use to get a maximum benefit interms of speed at which the log information is read ?
Restrictions
Owing to certain restrictions, i cannot use the database logging and reading approach
Will listening to the application eventLogs help in any way?
Thanks for the suggestions and time.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
默认跟踪侦听器将使用 win32 api OutputDebugString。您可以使用现有工具侦听传递给此方法的消息。看看这个,例如:
http://technet.microsoft.com/ en-us/sysinternals/bb896647.aspx
也许这会节省您编写自己的时间。
如果您确实想编写自己的代码,并且主要关心的是尽快将跟踪消息发送到跟踪查看器应用程序,那么您可以让 TraceListener 接受来自查看器的网络连接。每当跟踪侦听器处理跟踪消息时,您都会写入网络。如果您不关心能否在远程计算机上查看跟踪消息,那么当然,侦听放入 OutputDebugString 的内容也是一种选择。
当然,这会影响执行跟踪的应用程序的性能,因此写入网络最好异步完成,而不会阻止跟踪写入调用。在写入网络时,您必须将跟踪消息添加到队列中进行处理。
这是一个可能有效的简单示例:
The default trace listener will use the win32 api OutputDebugString. You can listen to messages passed to this method using existing tools. Have a look at this, for instance:
http://technet.microsoft.com/en-us/sysinternals/bb896647.aspx
Maybe that will save you the time it takes to write your own.
If you do want to write your own and your main concern is to get trace messages as fast as possible to the trace viewer application, then you could have your TraceListener accept network connections from the viewer. Whenever a trace messages is handled by the trace listener, you would write to the network. If you're not concerned about being able to view trace messages on a remote machine, then listening to whats put to OutputDebugString is also an option, of course.
This would effect the performance of the application doing the tracing of course so writing to the network is best done asynchronously without blocking the trace write call. While writing to the network you would have to add trace messages to a queue to process.
Here is a simple example which probably works:
为什么不使用 log4net 或 nlog ?
Why don't you use log4net or nlog ?