I am trying to listen for events in the Microsoft-Windows-NetworkProfile/Operational log. I can listen to the main Windows logs, such as the application log using this code:
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
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With