Digital Colony!

Log Events in Classic ASP to File System

Here is some code I created many years ago to log events on a web site using Classic ASP. All the code was placed into an include file called logEvent.asp.
logFile = "C:\SomePath"

Sub LogEvent (pageName, user, message)    
    Const ForWriting   = 2
    Const ForAppending = 8
    
    Set fs = CreateObject("Scripting.FileSystemObject")
    If fs.FileExists(logFile) Then
        Set logFile = fs.OpenTextFile(logFile, ForAppending)            
    Else
        Set logFile = fs.CreateTextFile(logFile, True)
    End If    
    
    logFile.WriteLine(Now() & vbTab & pageName & vbTab & user & vbTab & message)
    logFile.Close
    
    Set logFile = nothing
    Set fs = nothing
End Sub
Add this include line from each page you wish to use the Logging script.
<!--#include virtual="/inc/logEvent.asp" -->
The last step is to actually write to the log file.
Call LogEvent("Home", "Larry King", "Referred from Google")    

Labels: ,

posted by MAS on Oct 1,2007

Digital Colony Copyright © 1999-2010 XHTML   508
Try...Catch Disclaimer: For brevity many examples do not include error handling. That is your responsibility.