Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Read Event log file from path

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 unconnected machines. I get .evtx files then i try to process them. Right now i'm doing it from exported xml files. But i would like to skip the to xml conversion part. I've read the https://msdn.microsoft.com/en-us/library/System.Diagnostics.EventLog.aspx article but i didn't find what i was looking for. Is there a way to do what i want without converting to xml?

like image 220
PonuryCiastkarz Avatar asked Dec 18 '25 17:12

PonuryCiastkarz


1 Answers

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());
        }
    }        
}
like image 187
Mike Zboray Avatar answered Dec 20 '25 06:12

Mike Zboray



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!