Imports System.IO Imports System.Configuration.ConfigurationSettings PublicClass Log ' shortcut for appending text line breaks to strings Shared LineBreak AsString = Environment.NewLine '######################################################################################################################### ' Logs an ApplicationException object. These exceptions are custom exceptions defined by our own application '######################################################################################################################### SharedSub WriteLogEntry(ByVal ex As ApplicationException, ByVal ClassName AsString, ByVal MethodName AsString) Dim FS AsNew FileInfo(AppSettings("LogFileName")) Dim SW As StreamWriter = FS.AppendText() Dim Msg AsNew Text.StringBuilder() Msg.Append("Date: " + Now.ToLongDateString + " " + Now.ToLongTimeString()).Append(LineBreak) Msg.Append("Exception Message: " + ex.Message).Append(LineBreak) Msg.Append("Stack Trace: " + ex.StackTrace).Append(LineBreak).Append(LineBreak) SW.WriteLine(Msg.ToString()) SW.Close() EndSub '######################################################################################################################### ' Logs a generic Exception object '######################################################################################################################### SharedSub WriteLogEntry(ByVal ex As Exception, ByVal ClassName AsString, ByVal MethodName AsString) Dim FS AsNew FileInfo(AppSettings("LogFileName")) Dim SW As StreamWriter = FS.AppendText() Dim Msg AsNew Text.StringBuilder() Msg.Append("Date: " + Now.ToLongDateString + " " + Now.ToLongTimeString()).Append(LineBreak) Msg.Append("Exception Message: " + ex.Message).Append(LineBreak) Msg.Append("Stack Trace: " + ex.StackTrace).Append(LineBreak).Append(LineBreak) SW.WriteLine(Msg.ToString()) SW.Close() EndSub EndClass |