How do I specify events deep inside “Applications and Services Logs”?

巧了我就是萌 提交于 2019-12-07 14:10:29

问题


The following code snippet fires an event when an event is logged. The sample code works fine but the log I want to monitor is actually "Applications and Services Logs > Microsoft > Windows > Task Scheduler > Operational".

What do I insert in place of "Application" in the code sample?

...
EventLog myNewLog = new EventLog("Application", ".", "testEventLogEvent");                 

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

回答1:


The log name is Microsoft-Windows-TaskScheduler/Operational but I don't think you can access it using the EventLog class. I think that log is based on Event Tracing for Windows so you need to use the System.Diagnostics.Eventing.Reader namespace to access it.

The Event Log Scenarios page might be useful, in particular the How to: Subscribe to Events in an Event Log article might help you get started.

Update: The How to: Subscribe to Events in an Event Log code worked for me after I changed the log name (I also changed the query to request Level=4)...

EventLogQuery subscriptionQuery = new EventLogQuery(
    "Microsoft-Windows-TaskScheduler/Operational", PathType.LogName, "*[System/Level=4]");


来源:https://stackoverflow.com/questions/6669546/how-do-i-specify-events-deep-inside-applications-and-services-logs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!