Eventlog监听器 - 应用程序和服务

use*_*394 6 c# windows event-log windows-vista

有没有办法在生成(C#)时观察"应用程序和服务"的事件?我发现我不能使用WMI.

还有其他想法吗?

Raj*_*han 6

您可以订阅EventLog.EntryWritten事件

将条目写入本地计算机上的事件日志时发生.

来自MSDN:

    ....
    EventLog myNewLog = new EventLog();
    myNewLog.Log = "MyCustomLog";                      

    myNewLog.EntryWritten += new EntryWrittenEventHandler(MyOnEntryWritten);
    myNewLog.EnableRaisingEvents = true;                 

}       

public static void MyOnEntryWritten(object source, EntryWrittenEventArgs e){

}
Run Code Online (Sandbox Code Playgroud)