如何指定事件在内心深处与QUOT;应用程序和服务日志"?内心深处、应用程序、和服务、事件

2023-09-08 09:33:24 作者:追逐我的未来

下面code片段触发时记录事件的事件。样品code工作正常,但我要监控的日志实际上是应用程序和服务日志>微软>窗口>任务计划>运行。

我怎么插到位的code样本中的应用程序?

  ...
事件日志myNewLog =新事件日志(应用程序,testEventLogEvent。);

myNewLog.EntryWritten + =新EntryWrittenEventHandler(MyOnEntryWritten);
myNewLog.EnableRaisingEvents = TRUE;
...
 

解决方案

日志名为微软的Windows的TaskScheduler /运营,但我不认为你可以访问使用它的EventLog类。我认为,日志基于Windows事件跟踪,所以你需要使用的 System.Diagnostics.Eventing.Reader命名空间访问它。

借助事件日志方案页面可能是有用的,特别是如何:订阅事件在事件日志的文章可以帮助你开始了。

更新:该如何:订阅事件在事件日志中code为我工作后,我改变了日志名称(我也改变了查询请求级别= 4)..

  EventLogQuery subscriptionQuery =新EventLogQuery(
    微软的Windows的TaskScheduler /运行,PathType.LogName,* [系统/等级= 4]);
 

带你感受内心深处的未见之美,ELLE摄影师镜头下的影像视界

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;
...

解决方案

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]");