Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Eventlog listener - Applications and Services

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?

like image 617
user1011394 Avatar asked Apr 12 '12 18:04

user1011394


2 Answers

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){

}
like image 143
Raj Ranjhan Avatar answered Oct 23 '22 00:10

Raj Ranjhan


Did your try it wit the EventLog.EntryWritten Event?

like image 43
shriek Avatar answered Oct 23 '22 00:10

shriek