What's Here?
- Members: 300,415
- Replies: 826,017
- Topics: 137,454
- Snippets: 4,419
- Tutorials: 1,148
- Total Online: 1,574
- Members: 101
- Guests: 1,473
|
Open an error message log and append the message to it
|
Submitted By: Chubber
|
|
|
Rating:
|
|
Views: 962 |
Language: ASP
|
|
Last Modified: June 12, 2007 |
|
Instructions: This logs script actions to a file with the same name as the running script, keeping logging events seperate. Of course, you could change the file name. I often return early when I want to turn logging off, too. gDEBUG = True when I want to write to the browser. |
Snippet
Sub LogEvent(Message)
'Open an error message log and append the message to it
Dim LogFileName
LogFileName = "/log/" & Replace(Request.ServerVariables("URL"), "/", "_") & ".log"
Dim FO, OutFile
On Error Resume Next 'Will catch will IsObject()
Set FO = Server.CreateObject("Scripting.FileSystemObject")
If IsObject(FO) Then
Set OutFile = FO.OpenTextFile(Server.MapPath(LogFileName), 8, True)
If IsObject(OutFile) Then
OutFile.WriteLine(FormatDateTime(Now,2) & vbTab & FormatDateTime(Now,3) & vbTab & Message)
OutFile.Close
Set OutFile = Nothing
Else
'Could not create OutFile
If gDEBUG Then Response.Write "<BR>ERROR: In LogEvent(): Could Not create OutFile. LogFileName = " & LogFileName & " Maps to " & Server.MapPath(LogFileName) & vbCrLf
End If
Set FO = Nothing 'Close the object
Else
'Could not create FO
If gDEBUG Then Response.Write "<BR>ERROR: In LogEvent(): Could Not create FO." & vbCrLf
End If
On Error Goto 0
'If gDEBUG And Response.Buffer Then Response.Flush 'Write out any messages to the output stream.
End Sub
Copy & Paste
|
|
|
|