devxlogo

Basic Event Logging

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

See also  11 Effective Keyword Research Tools and Techniques
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist