【问题标题】:Using WMI to monitor event log使用 WMI 监控事件日志
【发布时间】:2012-01-13 03:07:52
【问题描述】:

我正在尝试使用 WMI 来监视 EntryWritten 事件的事件日志,因此我将处理程序设置如下:

// Create the event log monitor
        string query = "Select * From __InstanceCreationEvent Where TargetInstance.LogFile='Application'";
        WqlEventQuery aProcessCreationQuery = new WqlEventQuery(query);
        ManagementEventWatcher aWatcher = new ManagementEventWatcher(aProcessCreationQuery);
        aWatcher.EventArrived += new EventArrivedEventHandler(EventLogMonitor);

但我的处理程序方法 EventLogMonitor 永远不会触发,即使正在将内容写入应用程序事件日志。我的应用程序作为服务监控写入事件日志的内容运行。

我发现某处可能需要添加该行:

aWatcher.Start()

在 StartService() 方法中,但如果我这样做,服务将无法启动。我想知道是否有人对此有任何想法?

【问题讨论】:

    标签: c# wmi


    【解决方案1】:

    你的 WQL 句子是错误的 Select * From __InstanceCreationEvent Where TargetInstance.LogFile='Application'

    你必须使用ISA关键字在句子中包含你正在检查的类

    有点像

    Select * From __InstanceCreationEvent WHERE TargetInstance ISA 'Win32_NTLogEvent' and TargetInstance.LogFile='Application'

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-01-08
      • 2017-07-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-01
      相关资源
      最近更新 更多