VBcoders Browse New Submit Contact Sign In

No account? Register free

Forgot password?

clsLogFile

Bryan Johns  (2 Submissions)   Debugging and Error Handling   Visual Basic 3.0   Intermediate   Wed 3rd February 2021

This class module is very useful for keeping a standardized, formatted, event/error log for any application that might need one.

Inputs
See the comments in the code. Most should be self explanatory. The DaysToKeep property might be a little obscure. It's an integer value that tells the object how many days of log entries to keep when purging old entries during the Class Terminate process.

Assumes
Upon instantiating the object, set the DaysToKeep property to some integer value. The higher the value the further back in time the error.log entries will go. There are two basic usages of this class module. One is a generic error handler using the SimpleError method. This method should be called from any error handling routines you may have in your code. It takes as optional parameters the sub name and the form name of the code where it's being called. This is useful in tracking down where an error happened if a user calls for tech support. The other usage can be used to log events in code that you for whatever reason wish to log. For example, if you want to keep track of when a database file is opened and closed. In this usage you'd call the WriteLog method. This method takes several parameters. A string to hold the desired message, an optional parameter for the sub and for the form name, as well as an optional parameter to tell the object if this is a new entry or part of an existing one. For that last parameter, if true the message is handled like a new entry, enclosed in a block of *'s to make it easy to pick out from other messages. If false then it's treated as a continuation of the previous message. This allows multi-line messages.

Returns
Log entries are writte to a file called error.log which is stored in the application path. It is formatted with each individual log entry seperated by *'s and a header line showing which file or form and procedure generated the error.

Side Effects
If the DaysToKeep property is set too high it could result in a very large log file.

Rate clsLogFile (6(6 Vote))
clsLogFile.bas

clsLogFile Comments

No comments yet — be the first to post one!

Post a Comment

0/1000 characters