System Event Log Manager
The following code will explain you how to handle the system Event log. It will show how to write the event log and how to get the event log.
Name Space part
using System; using System.Resources; using System.Drawing; using System.Collections; using System.Diagnostics; using System.Windows.Forms; using System.Resources; using Microsoft.Win32;
In the above namespaces using System.Diagnostics is used for event log.
Create an Event log. We can create the event log by using the class EventLog. MyEventLog.WriteEntry has the following options
Syntax:
EventLog.WriteEntry(Registered event source,Event entry message, Event type ,Application-specific ID,Application-specific category, Event data );
The follosing code is used to create an event log
EventLog MyEventLog = new EventLog(); MyEventLog.log = "Application"; MyEventLog.Source = "www.Dotnetspider.com"; MyEventLog.WriteEntry("The member enterd into the webpage");
We can get the Event log entries by using the following code The following code will display 100 events in the log
for(int i = 0; i < 100; i++) { Console.WriteLine(MyEventLog.Entries[i].Message) Console.WriteLine(MyEventLog.Entries[i].MachineName) Console.WriteLine(MyEventLog.Entries[i].Source) Console.WriteLine(MyEventLog.Entries[i].TimeWritten) }
The following code is used to close the event log.
MyEventLog.Close();
By Nathan
|
No responses found. Be the first to respond and make money from revenue sharing program.
|