[英]How can I listen for events in the Microsoft-Windows-NetworkProfile/Operational log?
I am trying to listen for events in the Microsoft-Windows-NetworkProfile/Operational log. 我正在尝试在Microsoft-Windows-NetworkProfile / Operational日志中侦听事件。 I can listen to the main Windows logs, such as the application log using this code:
我可以使用以下代码收听主Windows日志,例如应用程序日志:
public static void SubscribeToLogEvents(string logName, EntryWrittenEventHandler customEventHandler)
{
EventLog log = new EventLog();
log.Log = logName;
//when an entry is written to an event log on the local computer, customEventHandler is fired
log.EntryWritten += customEventHandler;
//Set a value indicating EventLog receives
//System.Diagnostics.EventLog.EntryWritten event notifications.
log.EnableRaisingEvents = true;
}
static void EventLogEntryWritten(object sender, EntryWrittenEventArgs currentEvent)
{
var log = (EventLog)sender;
Console.WriteLine("Event Raised: |Log:{0}|Source:{1}|EventID:{2}|", log.LogDisplayName, currentEvent.Entry.Source, currentEvent.Entry.EventID);
}
If I use the following I can see events occurring in the Application log in real time: 如果我使用以下内容,我可以实时查看应用程序日志中发生的事件:
SubscribeToLogEvents("Application", OnEntryWritten);
However, the events I want are in here: 但是,我想要的事件在这里:
How can I listen to this log? 我怎么能听这个日志? If I try this:
如果我试试这个:
SubscribeToLogEvents("Microsoft-Windows-NetworkProfile/Operational", OnEntryWritten);
I get an error saying "Log Not Found". 我收到错误消息“找不到日志”。
Very late, but this was the first post I found on my quest to the answer. 很晚,但这是我在寻求答案时发现的第一篇文章。 So for people finding this at first:
所以对于最初发现这个的人来说:
private void AttachWatcher() {
EventLogQuery logQuery = new EventLogQuery("Microsoft-Windows-NetworkProfile/Operational", PathType.LogName, "*[System[(EventID = 10000)]]");
EventLogWatcher logWatcher = new EventLogWatcher(logQuery);
logWatcher.EventRecordWritten += new EventHandler<EventRecordWrittenEventArgs>(EventWritten);
logWatcher.Enabled = true;
}
private void EventWritten(Object obj, EventRecordWrittenEventArgs arg) {
//Do stuff
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.