May 8, 2009

C# - Export Windows Event Logs

Here is a little C# program to export Windows Event Logs. It reads an Event Log and prints entries to STDOUT so you can pipe the output to a file or other application.

using System;
using System.Diagnostics;


class EventLogExporter
{
    static void Main(string[] args)
    {
        EventLog evtLog = new EventLog("Application");  // Event Log type
        evtLog.MachineName = ".";  // dot is local machine
        
        foreach (EventLogEntry evtEntry in evtLog.Entries)
        {
            Console.WriteLine(evtEntry.Message);
        }
        
        evtLog.Close();
    }
}

3 comments:

Anonymous said...

I'll vote for Powershell in checking out the event log, provided you have the ability to install it.

Get-EventLog –list

More details here:

http://www.microsoft.com/technet/scriptcenter/topics/msh/cmdlets/get-eventlog.mspx

Anonymous said...

I said "ability" but I should have said "access rights"

ambreen said...

check this too and give it a try http://www.testertools.com/8907/ipLogger.html