如何从Windows XP 上的特定EventLogEntry
用途中获取 XML?C#
我已经知道EventLog
类型(安全)和事件条目 ID。
EventLogWatcher
和其他类仅在 Windows Vista 和更新版本中可用。
如何从Windows XP 上的特定EventLogEntry
用途中获取 XML?C#
我已经知道EventLog
类型(安全)和事件条目 ID。
EventLogWatcher
和其他类仅在 Windows Vista 和更新版本中可用。
您可以使用LogParser执行此操作。它是由 x Microsoft 员工 Gabriele Giuseppini 构建的实用程序,可读取大量日志文件格式 -快!
我之前已经成功地将它与事件日志一起使用。
http://visuallogparser.codeplex.com上的好人有一个 C# 接口
对于 Windows XP,您可以使用EventLogReader
和EventLogQuery
类EventLogRecords
非常有效地从事件日志中查询。此 API 从 .NET Framework 3.5 开始可用(因此它在 Windows XP 上应该可以正常工作)。
首先,您需要要查询的事件日志的名称(文件系统路径或名称),其次是用作记录选择器的 XPath 表达式。https://docs.microsoft.com/en-us/windows/win32/wes/sumption-events提供了一些示例
基本上,它的工作原理如下:
static string RetrieveApplicationEventDetailsXmlById(string eventId)
{
const string logName = "Application";
string queryExpression = string.Format("*[System/EventId=\"{0}\"]", eventId);
var eventLogQuery = new EventLogQuery(logName, PathType.LogName, queryExpression);
using (var reader = new EventLogReader(eventLogQuery))
{
EventRecord record;
if ((record = reader.Next()) != null)
{
return record.ToXml();
}
}
return null;
}
鉴于已经指定了一个有效的 XPath 表达式,对 readerNext
方法的调用将返回下一个可用对象,该对象允许通过该方法LogEventRecord
以 XML 格式检索事件的详细信息。ToXml