[免责声明]我是 C# 的新手,我不是程序员![/免责声明]
我正在按照此处的示例(C#: How to Query for an event log details with a given event id?)在自定义事件日志中搜索给定的 eventid。
该示例中的代码是:
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())
{
eventList.Add(eventInstance);
}
在我的应用程序中,我创建了一个名为“SMCLogs”的事件日志,LogSource 是“SAM2_SMCLogs”,所以我将上面的代码更改为如下:
string eventID = "330";
string LogSource = "SAM2_SMCLogs";
string sQuery = "*[SMCLogs/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())
{
eventList.Add(eventInstance);
}
但我收到错误:“找不到指定的频道。检查频道配置”
我究竟做错了什么?