Savings and Retriving Event Logs Them in VB.NET

Posted by Initiotech under VB.NET category on | Views : 3777
What are Event Logs?
Event Logs are files used by Windows OS to store the details of events,Such as memory allocation,error messages etc or userdefinded events.
In this application We will store a Simple Event Log using

Sub Main()
If Not EventLog.SourceExists("MyAppName") Then
EventLog.CreateEventSource("MyAppName", "AnyEventName")
Console.WriteLine("Event Source and Log Name created")
End If
Dim log As New EventLog()
log.Source = "MyAppName"
log.WriteEntry("This is a Simple Error Message Written In Event LOG", EventLogEntryType.Error)
log.WriteEntry("This is a Simple Warning Message Written In Event LOG", EventLogEntryType.Warning)
log.WriteEntry("This is a Simple Success Message Written In Event LOG", EventLogEntryType.SuccessAudit)
log.WriteEntry("This is a Simple Failure Message Written In Event LOG", EventLogEntryType.FailureAudit)
log.WriteEntry("This is a Simple Information Message Written In Event LOG", EventLogEntryType.Information)
Console.WriteLine("Events Written Successfully")
Console.WriteLine("First Message : " & log.Entries.Item(0).Message)
End Sub

The Event Will be stored You can view these log entry by going to

Control Panel ==> Administrative Tools ==> Event Viewer
We can Also View Those Logs Programtically using

Console.WriteLine("First Message : " & log.Entries.Item(0).Message)

Regards Hefin Dsouza

Comments or Responses

Login to post response