Read Event log file from path

前端 未结 1 370
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-23 07:38

My question is very similar to this one How do you open the event log programatically? Except i\'m logging anything. I need to create db of Log Entries from multiple unconnecte

相关标签:
1条回答
  • 2021-01-23 08:02

    Use 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());
            }
        }        
    }
    
    0 讨论(0)
提交回复
热议问题