VB写日志类

    技术2022-05-11  67

    Option ExplicitPublic gstrLogPath As String

    Private Sub Class_Initialize()    gstrLogPath = App.Path & "/Log"     'Log路径End Sub

    '*************************************************************************************************'*函数名:  WriteErrLog'*程序功能:写日志'*开发人员:inrg'*异动人员:无'*传入值:  1.strProgramName -- 类模块名'*          2.strProcName -- 函数名'*          3.strErrLog -- ErrorLog內容 eg:Err.Description'*          4.strErrNumber -- Err对象的错误编号(可选) eg:Err.Number'*          5.strErrDesc -- Err对象的错误描叙(可选) eg:Err.Description'*回传值:  boolean  成功 = true,失败 = false'*************************************************************************************************Public Static Function WriteErrLog(ByVal strProgramName As String, ByVal strProcName As String, ByVal strErrLog As String, Optional ByVal strErrNumber As String, Optional ByVal strErrDesc As String) As Boolean    Dim FileHandle As Long    Dim strTxtName As String        '    Dim FSOLog As Object            '        On Error GoTo WriteLogFileErr:

        Set FSOLog = CreateObject("Scripting.FileSystemObject")        WriteErrLog = True

        If (gstrLogPath = "") Then        WriteErrLog = False        GoTo WriteLogFileErr:    End If        '文件名    strTxtName = Format(Date, "YYYYMMDD") & ".log"        '判断是否有Log文件夹    If Dir(gstrLogPath, vbDirectory) = "" Then            MkDir gstrLogPath    End If

        FileHandle = FreeFile    Open (gstrLogPath & "/" & strTxtName) For Append As #FileHandle    Lock #FileHandle        Print #FileHandle, "************************************************************************"        Print #FileHandle, "Date & Time: " & Format(Time, "HH:MM:SS")        Print #FileHandle, "Program Name: " & strProgramName        Print #FileHandle, "Procedure Name: " & strProcName        Print #FileHandle, "Error Number: " & strErrNumber        Print #FileHandle, "Error Desc: " & strErrDesc        Print #FileHandle, "Log: " & strErrLog        Print #FileHandle, "************************************************************************" & vbNewLine    Unlock #FileHandle    Close #FileHandle        Set FSOLog = Nothing    Exit Function

    WriteLogFileErr:        WriteErrLog = FalseEnd Function 


    最新回复(0)