21 | 08 | 2017

Write Something in the Event Log

Use the code below to make a line of code into the Windows Event Log

  Public Function WriteToEventLog(ByVal Entry As String, _

       Optional ByVal AppDescr As String = "Your App Name", _
       Optional ByVal EventType As EventLogEntryType = EventLogEntryType.Information, _
       Optional ByVal LogName As String = "Application") As Boolean
        Dim EventObj As New EventLog()

            'Register the App
            If Not EventObj.SourceExists(AppDescr) Then
                EventObj.CreateEventSource(AppDescr, LogName)
            End If
            EventObj.Source = AppDescr

            EventObj.WriteEntry(Entry, EventType)
            Return True

        Catch Ex As Exception
            Return False
        End Try

    End Function

    Sub TestWritetoEventlog()

        'Write a simple line with default settings
        If WriteToEventLog("Type here the text you like to show in the event log") = True Then
        End If

    End Sub


Goto Start > Run and type eventvwr.msc to open the event log.

Below is a screenshot from a new event log entry.


Sign up now and upload your code to the website.

Help us to continue.....
Articles View Hits
Latest Articles