Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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. 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:

enter image description 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".

like image 432
Ben Avatar asked Sep 18 '25 21:09

Ben


1 Answers

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
}
like image 148
Rhaps Oldy Avatar answered Sep 20 '25 12:09

Rhaps Oldy