Hello Rob,
Check out the code below and in your appilcation make sure your suspect code
is in a Try, Catch block. You Should Be able to Copy and Paste, let me know
if this helps
'**********************************************************
'** Example For Your Code
'**********************************************************
Private Sub MyMethod
Try
Catch ex As Exception
WriteToErrorLog("MyMethod", ex.Message & vbCrlf & vbCrlf &
ex.StackTrace
End Try
End Sub
'**********************************************************
'** This Function Get The AppPath(Not The Bin, but the Project Folder)
'**********************************************************
Public Shared Function GetAppPath() As String
If Not Right(Microsoft.VisualBasic.CurDir.Replace("bin", ""), 1) =
"\" Then
Return Microsoft.VisualBasic.CurDir.Replace("bin", "") & "\"
Else
Return Microsoft.VisualBasic.CurDir.Replace("bin", "")
End If
End Function
'**********************************************************
'** This Method Will Write Any Errors To The ErrorLog Folder In Your Project
Folder
'**********************************************************
Public Shared Sub WriteToErrorLog(ByVal Sender As String, ByVal Message As
String)
Try
Dim FilePath As String = GetAppPath() & "ErrorLog\ErrorLog" &
Microsoft.VisualBasic.DateAndTime.Month(Now).ToString &
Microsoft.VisualBasic.DateAndTime.Day(Now).ToString & Year(Now).ToString &
".txt"
Dim SWriter As System.IO.StreamWriter
If System.IO.Directory.Exists(GetAppPath() & "ErrorLog") = False
Then System.IO.Directory.CreateDirectory(GetAppPath() & "ErrorLog")
If System.IO.File.Exists(FilePath) = False Then
SWriter = System.IO.File.CreateText(FilePath)
SWriter.WriteLine("*****************************************")
SWriter.WriteLine("** SENDER: " & Sender)
SWriter.WriteLine("** ERROR: " & Message)
SWriter.WriteLine("*****************************************")
SWriter.Flush()
SWriter.Close()
Else
SWriter = System.IO.File.AppendText(FilePath)
SWriter.WriteLine("*****************************************")
SWriter.WriteLine("** SENDER: " & Sender)
SWriter.WriteLine("** ERROR: " & Message)
SWriter.WriteLine("*****************************************")
SWriter.Flush()
SWriter.Close()
End If
Catch ex As Exception
MsgBox("There was a problem writing to the Error Log." & vbCrLf
& vbCrLf & "Please report this to World Touch Interactive.",
MsgBoxStyle.Exclamation, "Error Writing To File")
Application.Exit()
End Try
End Sub