Hi,

Does someone have a example to catch errors and log them to the Eventlog?

I would like to catch any error and pass them to my WriteToEventLog function.

If i use On Error , how could I catch the Error and pass it to my WriteToEventLog function?
I would like to catch the actual error



Public Function WriteToEventLog(ByVal entry As String, Optional ByVal appName As String = "CompanyName", Optional ByVal eventType As EventLogEntryType = EventLogEntryType.Information, Optional ByVal logName As String = "ProductName") As Boolean
'*************************************************************

'NAME: WriteToEventLog

'PURPOSE: Write to Event Log

'PARAMETERS: Entry - Value to Write

' AppName - Name of Client Application. Needed

' because before writing to event log, you must

' have a named EventLog source.

' EventType - Entry Type, from EventLogEntryType

' Structure e.g., EventLogEntryType.Warning,

' EventLogEntryType.Error

' LogNam1e: Name of Log (System, Application;

' Security is read-only) If you

' specify a non-existent log, the log will be

' created

'RETURNS: True if successful

'*************************************************************
Dim objEventLog As New EventLog

Try

'Register the Application as an Event Source

If Not EventLog.SourceExists(appName) Then
EventLog.CreateEventSource(appName, logName)
End If

'log the entry

objEventLog.Source = appName
objEventLog.WriteEntry(entry, eventType)

Return True

Catch Ex As Exception

Return False

End Try

End Function