从路径读取事件日志文件

Read Event log file from path

我的问题和这个很相似How do you open the event log programatically? 除了我正在记录任何东西。我需要从多台未连接的机器创建日志条目的数据库。我得到 .evtx 文件,然后尝试处理它们。现在我正在从导出的 xml 文件中进行操作。但我想跳过 to xml 转换部分。我已阅读 https://msdn.microsoft.com/en-us/library/System.Diagnostics.EventLog.aspx 文章,但没有找到我要找的内容。有没有办法在不转换为 xml 的情况下做我想做的事?

使用System.Diagnostics.Eventing.Reader.EventLogReader:

using (var reader = new EventLogReader(@"path\to\log.evtx", PathType.FilePath))
{
    EventRecord record;
    while((record = reader.ReadEvent()) != null)
    {
        using (record)
        {
            Console.WriteLine("{0} {1}: {2}", record.TimeCreated, record.LevelDisplayName, record.FormatDescription());
        }
    }        
}