Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Windows,C#:从活动和保存的日志中读取事件日志条目_C#_.net_Windows - Fatal编程技术网

Windows,C#:从活动和保存的日志中读取事件日志条目

Windows,C#:从活动和保存的日志中读取事件日志条目,c#,.net,windows,C#,.net,Windows,我知道我可以通过以下方式读取Windows PC的安全日志: var securityLog = new EventLog("security"); foreach (EventLogEntry entry in securityLog.Entries) { ... } 条目项包含我希望看到的所有有趣的日志字段,如:InstanceId、Message和其他。我现在要做的是从事件日志中读取相同的内容,该日志作为.evtx文件保存到磁盘 我已经看到了使用的建议 string xpathQ

我知道我可以通过以下方式读取Windows PC的安全日志:

var securityLog = new EventLog("security");
foreach (EventLogEntry entry in securityLog.Entries) {
    ...
}
条目
项包含我希望看到的所有有趣的日志字段,如:
InstanceId
Message
和其他。我现在要做的是从事件日志中读取相同的内容,该日志作为
.evtx
文件保存到磁盘

我已经看到了使用的建议

string xpathQuery = "*";

var eventsQuery = args.Length == 0
    ? new EventLogQuery("Security", PathType.LogName, xpathQuery)
    : new EventLogQuery(args[0], PathType.FilePath, xpathQuery);

using (var eventLogReader = new EventLogReader(eventsQuery)) {
    EventLogRecord entry;

    while ((entry = (EventLogRecord) eventLogReader.ReadEvent()) != null) {
        ...
    }
}
但是第二个版本中的
条目
与第一个示例中的成员/值不同。我完全明白我很困惑,并且用错误的方式看待这个问题

如何从活动或保存的系统日志中读取每个记录的实际内容


或者,我可以从
EventLogRecord
转到
EventLogEntry
?我还没有看到这种转换方法。

这不是一个完整的答案,但我已经做到了一半。一位好友发现,在我的第二种方法中,我可以使用
entry.FormatDescription()
获取事件“消息”
entry.Id
实例Id
。但我只看到一个日期字段。有一组“属性”,但我不确定如何以命名方式访问它们。但我更接近了