|
''' <summary>
''' Error Handling Module
''' By chemnoor@gmail.com
''' </summary>
Friend Module _ErrMsg
Public Sub ErrMsg(ByVal sMsg As String, Optional ByVal bShow As Boolean = False _
, Optional ByVal LogFileName As String = "", Optional ByVal LogOnce As Boolean = False)
'NEH
'My.Application.Log.WriteEntry()
On Error Resume Next
Static sMsgs As New Collections.Generic.List(Of String)
LogFileName = LogFileName.Trim
If Left(sMsg, 1) <> "<" OrElse Not LogOnce Then
If sMsgs.Contains(sMsg) Then Exit Sub
sMsgs.Add(sMsg)
End If
Const scPath As String = "C:\Temp"
Static sLogFileName As String
Dim sLogFileName0 As String
Dim iFile As Integer
iFile = FreeFile()
If Not IO.Directory.Exists(scPath) Then MkDir(scPath)
If LogFileName <> "" Then
sLogFileName0 = "C:\Temp\" & LogFileName & ".txt"
Else
sLogFileName0 = "C:\Temp\" & "Errors.txt"
End If
If sLogFileName <> sLogFileName0 Then
If FileLen(sLogFileName) > 100 * 1024 Then
Kill(sLogFileName)
End If
FileOpen(iFile, sLogFileName, OpenMode.Append, OpenAccess.Write)
Print(iFile, vbNewLine & vbNewLine & "Date: " _
& Now.ToString("yyyy/MM/dd HH:mm:ss") & vbNewLine)
FileClose(iFile)
sLogFileName = sLogFileName0
End If
iFile = FreeFile()
FileOpen(iFile, sLogFileName, OpenMode.Append, OpenAccess.Write)
Print(iFile, vbNewLine & vbNewLine & "Date: " _
& Now.ToString("yyyy/MM/dd HH:mm:ss") & vbNewLine)
Print(iFile, sMsg)
FileClose(iFile)
If bShow Then
On Error Resume Next
MsgBox(sMsg)
End If
End Sub
Public Sub ErrMsg(ByVal ex As Exception)
'NEH
If ex Is Nothing Then Exit Sub
Dim sMsgs = ex.Message & vbNewLine & ex.StackTrace & vbNewLine
ErrMsg(sMsgs)
#If DEBUG Then
'#
#End If
End Sub
End Module
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
ASP.Net Hosting on Linux server
---------------------------
There is a developer behind every piece of code!
DNA is too complex what about it!
No junk DNA; There is a functional role for noncoding DNA