如何根据日志类型过滤日志(根据调试事件或异常)? [英] How to filter logs according to type of log (as per debug event or exception)?

查看:175
本文介绍了如何根据日志类型过滤日志(根据调试事件或异常)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为标准应用程序运行创建一个 Logging Mechanism

我想将我的日志过滤成两个不同的类别,以便控制日志记录。

类别:

1.Exceptions

2.Debug事件。

是否有任何属性可以区分这两个事件?

I am creating a Logging Mechanism for a standard application run.
I want to filter my logs into two different categories, in order to control the logging.
Categories are :
1.Exceptions
2.Debug events.
Is there any property which can differentiate between the two events?

推荐答案

您可以使用枚举系统。 Diagnostics.EventLogEntryType

http ://msdn.microsoft.com/en-us/library/vstudio/system.diagnostics.eventlogentrytype [ ^ ]。



这是使用此类型的方法之一: http://msdn.microsoft.com/en-us/library/vstudio/f6wy11we [ ^ ]。



此外,你可以有几个不同的事件源,并根据它引入任意分类: http://msdn.microsoft.com/en-us/library/vstudio/2awhba7a [ ^ ]。



但是,考虑到你的目的,在标准系统事件查看器显示的事件日志树中隔离一些分支以显示特定于应用程序的事件与其他事件分开将更有用。不幸的是,这种方法需要一些卸载,以便在不再需要时清理目标系统。如果您要使用安装程序部署您的产品并使用安装程序启用,那么这将不是问题,如果没有,您需要单独关注此类清理。请看我过去的答案:

如何在文件夹下创建事件日志 [ ^ ]。



-SA
You can use the enumeration System.Diagnostics.EventLogEntryType:
http://msdn.microsoft.com/en-us/library/vstudio/system.diagnostics.eventlogentrytype[^].

This is one of the methods using this type: http://msdn.microsoft.com/en-us/library/vstudio/f6wy11we[^].

Besides, you can have several different "event sources" and introduce any arbitrary classification based on that: http://msdn.microsoft.com/en-us/library/vstudio/2awhba7a[^].

But, looking at your purpose, it would be even more useful to isolate some branches on the event log tree shown by the standard system event viewer to show events specific to your applications separately from other events. Unfortunately, this method will require some uninstallation, to clean up the target system when this is no longer needed. If you are going to deploy your product with logging enables with the use of installer, it won't be a problem, if not, you would need to take care about such clean up separately. Please see my past answer:
How to create event log under a folder[^].

—SA


这篇关于如何根据日志类型过滤日志(根据调试事件或异常)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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