Basic Event Logging

Any production application should include event logging for troubleshooting and auditing purposes. This code can be placed in any module and called whenever you have an error or event that you want to log.

 Public Function LogEvent(sFileName As String, sEvent As String) As Boolean'**********************************************************************'   Use to log errors or any other events, useful for audits and troubleshooting'   SYNTAX: if LogEvent( app.path & "" & app.title & "Log.txt", "System Exploded") = True then ....'   Bob Feldsien, MSCD'*********************************************************************Dim ff As LongOn Error GoTo ErrHandler       ff = FreeFile    Open sFileName For Append As #ff    '   Will create file if it doesn't already exist    Print #ff, Now() & ": " & sEvent    Close #ff    LogEvent = True    Exit FunctionErrHandler:    LogEvent = False    Exit FunctionEnd Function Public Function DeleteLog(sFileName As String) As Boolean'   Call from Sub Main to recreate file every time app is run'   SYNTAX: DeleteLog app.path & "" & app.title & "Log.txt"    On Error Resume Next    If Dir(sFileName) <> "" Then Kill sFileName    DeleteLog = True    '   if previous line fails, then file didn't exist anywayEnd Function

Share the Post:
Share on facebook
Share on twitter
Share on linkedin

Overview

Recent Articles: