如何在Microsoft-Windows-NetworkProfile / Operational日志中侦听事件?

时间:2016-05-19 19:45:57

标签: c# logging event-handling

我正在尝试在 Microsoft-Windows-NetworkProfile / Operational 日志中侦听事件。我可以使用以下代码收听主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);

}

如果我使用以下内容,我可以实时查看应用程序日志中发生的事件:

SubscribeToLogEvents("Application", OnEntryWritten);

但是,我想要的事件就在这里:

enter image description here

我该如何收听此日志?如果我试试这个:

SubscribeToLogEvents("Microsoft-Windows-NetworkProfile/Operational", OnEntryWritten);

我收到错误消息“找不到日志”。

1 个答案:

答案 0 :(得分:2)

很晚,但这是我在寻求答案时发现的第一篇文章。所以对于最初发现这一点的人来说:

def __mul__(self, other):
    ...
    if isinstance(other, Interval):
        s2, f2= other.s, other.f
        return Interval(...)
    return NotImplemented

def __rmul__(self, other):
    return self.__mul__(other)