在C#中查询事件日志中消息内容的最简单方法是什么? [英] What is the simplest way to query event logs for message contents in C#?

查看:98
本文介绍了在C#中查询事件日志中消息内容的最简单方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对编写一些代码以查询Windows事件日志中特定的错误消息内容感兴趣,如

I'm interested in writing some code to query the Windows Event Log for specific error message contents, as described in this MSDN article. However, I'm not a big fan of the mechanic of basically hand-rolling XPATH or a custom event view in the code...is there a simpler way of doing this? A LINQ provider perhaps?

推荐答案

您可以在事件查看器中创建自定义视图,然后复制生成的XML.架构完全相同.

You can create a custom view in Event Viewer and copy the generated XML. The schema is exactly the same.

另一种选择是一次读取一次事件,并使用字符串搜索,XPATH或LINQ to XML检查事件的内容.显然,这不是最可扩展的解决方案,尤其是在查询远程服务器时.

The other option is to read the events one at a time and check their contents using string searches, XPATH or LINQ to XML. Obviously, not the most scalable solution, especially when querying remote servers.

使用Google搜索可以查找一些似乎正在使用LINQ查询事件日志的示例,但实际上它们只是枚举所有条目.似乎没有任何提供者会真正将LINQ查询转换为正确的XML并返回结果

Googling can turn up some samples that seem to be using LINQ to query the Event Log but they really just enumerate over all the entries. There doesn't seem to be any provider that will really convert a LINQ query to the proper XML and return the results

这篇关于在C#中查询事件日志中消息内容的最简单方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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