Build an ASPLogger DLL
Create a DLL for your ASP pages that logs information and error messages on your Web server.
by Stan Schultes
November 2002 Issue
Technology Toolbox: VB6, ASP
Web developers rely on server logs for information about how a Web site is running. They can see visitors' IP addresses, pages they've visited on the site, Web server status messages, and more, depending on the log content chosen to output from the Web server software. Most Web developers and administrators use Web server logs to help them organize, analyze, and report this output.
However, Web server logs are designed to show Web server activity—not information about your Web applications. Errors generated by your apps show up as generic messages and can get lost in the potentially huge logs generated by Web servers such as Internet Information Server (IIS).
I'll show you how to build a logging component with VB6 that you call from your ASP pages (download the sample application here). ASPLogger provides two types of logging: error and trace output. You might think of these as being high- and low-priority messages you can control independently. These address your needs for customized Web app error reporting and output.
You build the DLL, then install and register it on your Web server. Create an instance of the ASPLogger object in Active Server Pages (ASP), initialize it, and call either LogInfo or LogError to write out your data. Error and information output can go into separate log files or into a single file. For safety, ASPLogger only writes files with a LOG extension into the current Web's virtual directory path. The LoggingEnabled property controls all logging, while the InfoEnabled property lets you control only the Info logging. This way, you can turn debug and trace output on and off independent of error output.
Build three public methods and nine public properties into ASPLogger (see Table 1). Use the Init method to set the logger object's startup properties; you can set any of its properties at run time to change your startup settings. This VBScript code in an ASP page declares and creates the logger object, then writes an info entry:
<%dim oLog
Set oLog = Server.CreateObject _
("ASPLogger.ASPLog")
oLog.Init Server, Request, _
"ASPLogTest", "V1.00.00"
oLog.LogInfo "Page Initialized"%>
The code passes ASP Server and Request object references—along with the page name and version—to the ASPLog Init method. The Init method also takes optional parameters for the other properties (see Listing 1). You must call Init from your ASP page to enable ASPLogger for output.
ASPLogger is designed to run from ASP pages, so it declares all method and property parameters and returns values as variants, because classic ASP allows only variant data types in a Web page. The ASPLogger object works with ASP.NET, but it's designed for ASP versions 2 or 3 (Windows 98/NT or 2000/XP).
Back to top
|