Eventlog listener - Applications and Services

后端 未结 2 899
臣服心动
臣服心动 2021-01-05 16:08

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条回答
  • 2021-01-05 16:16

    Did your try it wit the EventLog.EntryWritten Event?

    0 讨论(0)
  • 2021-01-05 16:25

    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){
    
    }
    
    0 讨论(0)
提交回复
热议问题