Display top 10 entries from the Event log

Description :


We can get top 10 entries from the event log by using
the following code.

The name space using System.Diagnostics takes important part in this
requirement

Name Space Part

using System;
using System.Resources;
using System.Drawing;
using System.Collections;
using System.Windows.Forms;
using System.Diagnostics;
using Microsoft.Win32;
using System.Resources;



Coding Part

class MyEventLogClass
{
static void Main(string[] args)
{
EventLog MyEventLog = new EventLog();
MyEventLog.Log = "Application";
MyEventLog.Source = "www.Dotnetspider.com";
MyEventLog.WriteEntry("Testing message");

for(int count = 0; count < 10; count++)
{
Console.WriteLine("Message: " + MyEventLog.Entries[count].Message );
Console.WriteLine("Machine: " + MyEventLog.Entries[count].MachineName );
Console.WriteLine("Sounce : " + MyEventLog.Entries[count].Source );
Console.WriteLine("Time : " + MyEventLog.Entries[count].TimeWritten);

}
MyEventLog.Close();
}
}


Code Explanation

1. Create the instance of the Eventlog.
2. By using the for loop we can get the entries
3. get the events from that entry

By
Nathan


Comments

No responses found. Be the first to comment...


  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: