如何写错误日志

'BaseFunction

 

'测试开关

Public Enum TYPE_TestFlag

    OutExe = 0 '0-输出到DebugView --;

    OutTxt ='1-输出到日志文件--;

    OutBath = 2 '2-输出到DebugView 也输出到日志文件--;

    OutNull = 3 '3-无错误输出--;

End Enum

 

'测试开关常量

Private Const m_TestFlag = TYPE_TestFlag.OutBath

 

 

'写日志文件

Public Sub WriteErrFile(ByVal strMsg As String)

    On Error GoTo ErrHandle

 

    Dim nFileID As Integer

    Dim strFileName As String

 

    strFileName = App.path + "\我的程序.dat"

    strMsg = "ErrTime:" + CStr(Now) + ";ErrDes:" + "我的程序->" + strMsg

 

    Select Case m_TestFlag

        Case TYPE_TestFlag.OutExe

            Call OutputDebugString(strMsg)

            Exit Sub

        Case TYPE_TestFlag.OutTxt

            nFileID = FreeFile

            Open strFileName For Append As #nFileID

            Write #nFileID, strMsg

            Close nFileID

            Exit Sub

        Case TYPE_TestFlag.OutBath

            Call OutputDebugString(strMsg)

            nFileID = FreeFile

            Open strFileName For Append As #nFileID

            Write #nFileID, strMsg

            Close nFileID

            Exit Sub

        Case TYPE_TestFlag.OutNull

            Exit Sub

        Case Else

            Exit Sub

    End Select

 

ErrHandle:

    Err.Clear

    Resume Next

 

End Sub

posted @ 2009-11-28 23:37  邓维  阅读(359)  评论(0编辑  收藏  举报