Site Search:
Sign in | Join | Help
4Penny.net

VB.NET

Notes, Tricks and Tips on VB.NET

How to write to the application event log using VB.NET

Here a sample of code that will write to the application event log, using VB..NET:

 

 Public Function WriteToEventLog(ByVal Entry As String)


    Dim appName As String = "Server Maintenance"
    Dim eventType As EventLogEntryType = EventLogEntryType.Error
    Dim logName = "Application"


    Dim objEventLog As New EventLog()


    Try
        'Register the App as an Event Source
        If Not EventLog.SourceExists(appName) Then
            EventLog.CreateEventSource(appName, logName)
        End If


        objEventLog.Source = appName


        'WriteEntry is overloaded; this is one
        'of 10 ways to call it
        objEventLog.WriteEntry(Entry, eventType)
        Return True
    Catch Ex As Exception
        Return False


    End Try


End Function

Comments

No Comments

Leave a Comment

(required)  
(optional)
(required)  
Add

About Steve Gray

Steve is a seasoned (translate: old) developer in VB and ASP.NET. He spends most of his time in Dynamics GP, writing custom mods for consulting firms. Crystal reports, eConnect, VS Tools for Dynamics... anything that comes along.