Over the weekend, I put together some code for logging Errors and Execution times for my journals. This helps me identify unforeseen errors and keeps time saving metrics. I have posted my code below and was curious if any other NX Journalers have put anything similar together. I would also be interested in any ideas or modifications you might have to improve this code.
Sub LogError(ErrorType As String, ErrorMessage As String)
Using ErrorWriter As New IO.StreamWriter(Path.GetDirectoryName(theSession.ExecutingJournal) & "\LogError.txt", True)
ErrorWriter.Write(vbCrLf + "Log Entry : ")
ErrorWriter.WriteLine("{0} {1}", DateTime.Now.ToLongTimeString(), DateTime.Now.ToLongDateString())
ErrorWriter.WriteLine(ErrorMessage)
ErrorWriter.WriteLine("--------------------------------------------------------------")
ErrorWriter.Close
End Using
End Sub
Sub LogTime(Time As TimeSpan)
Dim OldTime As TimeSpan
Using TimeReader As StreamReader = New StreamReader(Path.GetDirectoryName(theSession.ExecutingJournal) & "\LogTime.txt")
OldTime = TimeSpan.Parse(TimeReader.ReadLine())
TimeReader.Close
End Using
Using TimeWriter As New IO.StreamWriter(Path.GetDirectoryName(theSession.ExecutingJournal) & "\LogTime.txt", False)
TimeWriter.WriteLine(Time.Add(OldTime).ToString)
TimeWriter.Close
End Using
End Sub