0 Replies - 949 Views - Last Post: 12 June 2007 - 05:21 AM

#1 Chubber  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 0
  • View blog
  • Posts: 131
  • Joined: 16-October 06

LogEvent

Posted 12 June 2007 - 05:21 AM

Description: 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. Open an error message log and append the message to it
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 "
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 "
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


Is This A Good Question/Topic? 0
  • +

Page 1 of 1