C#中:如何查询与给定事件ID的事件日志的详细信息? [英] C#: How to Query for an event log details with a given event id?
问题描述
1)如何知道一个特定事件(特定的事件ID,时间和节点输入)是否记录或没有? [在这种情况下,我只知道一个事件将被记录]
1) How to know whether a particular event (given event ID, time and node as inputs) is logged or not? [In this case, I know only one event will be logged]
2)如果记录的情况下,我怎么得到这样的事件描述的详细信息,登录名等。
2) If the event is logged, how do I get details like event description, Log-name etc..
对于如我希望节点应用程序和服务日志下查询事件>微软> Windows>系统GroupPolicy中>运算和事件ID是5315和时间是当前时间。
for eg, I want to query for an event under the node Applications and Services Logs > Microsoft > Windows > groupPolicy > Operational, and event id is 5315 and time is current time.
推荐答案
有一些新的波折,如果你要查询从新款的Windows EventLogs事件。
There are a few new twists if your going to query events from the new style Windows EventLogs.
- 您将不得不使用的类从System.Diagnostics.Eventing.Reader命名空间读取新的事件。
- 您的查询将在Xpath的形式,让timerage是棘手的,请参阅MSDN的 EventLogQuery定义。
- 您的程序会遇到访问问题,准备冒充包括伐木机上EventReaders AD组这就是用户。
本示例展示了一些新的接入方式,欢呼声。
This sample shows some of the new access methods, cheers.
string eventID = "5312";
string LogSource = "Microsoft-Windows-GroupPolicy/Operational";
string sQuery = "*[System/EventID=" + eventID + "]";
var elQuery = new EventLogQuery(LogSource, PathType.LogName, sQuery);
var elReader = new System.Diagnostics.Eventing.Reader.EventLogReader(elQuery);
List<EventRecord> eventList = new List<EventRecord>();
for (EventRecord eventInstance = elReader.ReadEvent();
null != eventInstance; eventInstance = elReader.ReadEvent())
{
//Access event properties here:
//eventInstance.LogName;
//eventInstance.ProviderName;
eventList.Add(eventInstance);
}
这篇关于C#中:如何查询与给定事件ID的事件日志的详细信息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!