Search this blog

Monday, August 17, 2009

Read Event Log using C#

The Following sample code helps to Read Data from Event Log. This is a sample windows application written by using C#.

In the following sample code, I used 2 controls, Listbox and EventLog Controls.

Set the Log Property of Eventlog control to name of the log to read or write. I selected System Log to test this code

In the Form Load Event, I written the following code,

foreach (System.Diagnostics.EventLogEntry entry in eventLog1.Entries)
{
listBox1.Items.Add(entry.EntryType.ToString() +
" - " + entry.TimeWritten + " - " + entry.Source + " - " + entry.UserName);
}

This code, read the Data from Log file and written display in to listbox control.

Now if run the code, it will display as shown in screen shot

3 comments:

  1. Windows Event Helper C# "Integration with EventLog"::
    http://ledomoon.blogspot.com/2008/08/windows-event-helper-c-with-eventlog.html

    ReplyDelete
  2. thanks 4 this tutorial this tutorial help to view event log entries

    Best Regards from MANAS

    ReplyDelete