Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Public Sub LogError(ByVal ex As System.Exception, Optional ByVal CustomMsg As String = "")
- Console.Beep() ' audio alert to alert user that an error just got hit
- Dim MessageBody, Subject As String
- Dim st = New StackTrace() ' for retrieving the CALLING function name
- Try
- MessageBody = "Custom Message: " & CustomMsg & vbNewLine & "Exception: " & ex.Message & vbNewLine
- Subject = "Error in " & My.Application.Info.AssemblyName
- MessageBody = MessageBody & "Function: " & st.GetFrame(1).GetMethod().Name & vbNewLine &
- "Machine Name: " & My.Computer.Name & vbNewLine &
- "Version: " & My.Application.Info.Version.ToString & vbNewLine &
- "DateTime: " & Now & vbNewLine &
- "Full Exception Detail: " & ex.ToString & vbNewLine
- If ex.InnerException IsNot Nothing Then ' if there is an inner exception too, include it in the message
- MessageBody = MessageBody & vbNewLine & "Inner Exception Detail: " & ex.InnerException.ToString
- End If
- SendEmail(0, 0, "youremail@gmail.com", Subject, MessageBody)
- Catch ex2 As Exception
- Debug.WriteLine("couldn't send error email for " & CustomMsg)
- End Try
- End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement