.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Melody Anderson
Eminent IT

Home >> Code Snippets >> Visual Studio >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Using System Event Log To Store Important Messages.

Posted By:Hefin Dsouza       Posted Date: August 11, 2009    Points: 10    Category: Visual Studio    URL: http://www.dotnetspark.com  

Using System Event Log To Store Important Messages.

First we have to Know What Are Event Logs?
Event Logs are files used by MS Windows to store the details of important events,Such as memory allocation etc or userdefinded events.

In this application We will store a Simple Event Log using VB.net

    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 VB.net

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

Regards Hefin Dsouza


Further Readings:


No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend