如何指定“应用程序和服务日志”深处的事件?
以下代码片段在记录事件时触发事件。示例代码工作正常,但我想要监视的日志实际上是“应用程序和服务日志 > Microsoft > Windows > 任务计划程序 > 操作”。
我应该在代码示例中插入什么来代替“应用程序”?
...
EventLog myNewLog = new EventLog("Application", ".", "testEventLogEvent");
myNewLog.EntryWritten += new EntryWrittenEventHandler(MyOnEntryWritten);
myNewLog.EnableRaisingEvents = true;
...
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;
...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
日志名称是 Microsoft-Windows-TaskScheduler/Operational 但我认为您无法使用 EventLog 类访问它。我认为该日志基于 Windows 事件跟踪,因此您需要使用 System.Diagnostics.Eventing.Reader 命名空间 来访问它。
事件日志方案页面可能很有用,特别是如何:订阅事件日志中的事件一文可能对您有帮助开始吧。
更新:如何:在事件日志中订阅事件代码在我更改日志名称后对我有用(我还更改了查询以请求 Level=4)...
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)...