我正在尝试检索一些与应用程序不同类别的事件日志.例如,我想在"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())); }更多推荐
如何检索“应用程序"类别以外的事件日志?
发布评论