Eventlog listener - Applications and Services

2020-03-02 08:30发布

Is there a way to watch events of "applications and services" when they are generated (in C#)? I've figured out that I can not use WMI for it.

Any other ideas?

2条回答
走好不送
2楼-- · 2020-03-02 08:46

You can subscribe to EventLog.EntryWritten Event

Occurs when an entry is written to an event log on the local computer.

From MSDN:

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

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

}       

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

}
查看更多
ゆ 、 Hurt°
3楼-- · 2020-03-02 08:52

Did your try it wit the EventLog.EntryWritten Event?

查看更多
登录 后发表回答