Application Logging Class

Category:
Miscellaneous
Type:
Classes
Difficulty:
Intermediate
Author:
Matthew Inns

Version Compatibility: Visual Basic 6

More information:
This class provides a logging object that you can create and destroy as you like, the properties it has are:

	CurrentProcedure 
	LogFile LogLevel 
	MaxFileIterations 
	MaxFileSize 

The methods are:

	BeginLogging 
	StopLogging 
	Log 
Create a global clsLogger object, then in each procedure you can pass the name of the procedure as a string to .CurrentProcedure.

Anytime you want to log some data, use the Log method to write out to the file.

The logfile is kept open for the duration of your application to save time, the WriteFile API is used for this purpose also.

The Log method takes the LogLevel of the message, the message itself and a parameter array of other data you'd like to write to the file.

The levels work like this: clslogger.LogLevel is set at 3, a Log command is processed passing a level of 5, Log will not write it out to the file .

clslogger.LogLevel is set at 3, a Log command is processed passing a level of 2, Log will write it out to the file.

This way, you can up or down the level of logging to conserve log file size.

LogFile is the name of the file to be logged to, it will have a .Log extension, unless you make use of the File Iteration feature. LogFile is the name of the initial logfile, without an extension.

File Iteration allows you to save logs to files until they reach a certain size(MaxFileSize), it will then change the extension to 002, 003 etc., until MaxFileIterations is met, then it will revert back to 001 again.

A sample form is provided giving some idea of how to use the logger object.

Regards, Matthew Inns
http://www.zilpher.com


Instructions: Click the link below to download the code. Select 'Save' from the IE popup dialog. Once downloaded, open the .zip file from your local drive using WinZip or a comparable program to view the contents.

Download application_logger.zip