gpt4 book ai didi

c# - 如何监听 Microsoft-Windows-NetworkProfile/操作日志中的事件?

转载 作者:行者123 更新时间:2023-11-30 15:21:34 31 4
gpt4 key购买 nike

我正在尝试监听 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);

我收到一条错误消息“未找到日志”。

最佳答案

很晚了,但这是我在寻找答案时找到的第一篇文章。所以对于一开始发现这个的人来说:

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
}

关于c# - 如何监听 Microsoft-Windows-NetworkProfile/操作日志中的事件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37332692/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com