如何检索“应用程序"类别以外的事件日志?

编程入门 行业动态 更新时间:2024-10-24 08:25:49
本文介绍了如何检索“应用程序"类别以外的事件日志?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试检索一些与应用程序不同类别的事件日志.例如,我想在"Microsoft-Windows-Application Server-Applications/Operational"中获取信息.下面是我的代码

I'm trying to retrieve some event log in a category that is different from Application. For example, I want to get the info in "Microsoft-Windows-Application Server-Applications/Operational". Below it is my code

EventLog log = new EventLog("Microsoft-Windows-Application Server-Applications/Operational"); int index = log.Entries.Count - 1; Debug.WriteLine(log.Entries[index].Message);

但是它总是显示错误:

The event log 'Microsoft-Windows-Application Server-Applications/Operational' on computer '.' does not exist.

如果仅使用应用程序",则可以在应用程序"类别中获取日志.

If I simply use "Application", then I can get the log in Application category.

如何获取"Microsoft-Windows-Application Server-Applications/Operational"的日志?

How to get log for "Microsoft-Windows-Application Server-Applications/Operational"?

谢谢

推荐答案

EventLog类仅允许您访问Windows事件日志.您将要使用在System.Diagnostics.Eventing.Reader名称空间中找到的EventLogReader.

The EventLog class only lets you access Windows event logs. You will want to use instead the EventLogReader found in System.Diagnostics.Eventing.Reader namespace.

EventLogQuery query = new EventLogQuery("Microsoft-Windows-Application Server-Applications/Operational", PathType.LogName, "*"); EventLogReader reader = new EventLogReader(query); EventRecord eventRecord; while ((eventRecord = reader.ReadEvent()) != null) { Console.WriteLine(String.Format("{0} - {1}", eventRecord.TimeCreated, eventRecord.FormatDescription())); }

更多推荐

如何检索“应用程序"类别以外的事件日志?

本文发布于:2023-11-11 07:54:24,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1577810.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:应用程序   类别   事件   日志   quot

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!