ASP.NET School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

 

Code Snippets

  

ASP Source Code


Welcome to Dream.In.Code
Become a ASP.NET Expert!

Join 300,415 ASP.NET Programmers for FREE! Get instant access to thousands of ASP.NET experts, tutorials, code snippets, and more! There are 1,574 people online right now. Registration is fast and FREE... Join Now!





LogEvent

Open an error message log and append the message to it

Submitted By: Chubber
Actions:
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


  1. Sub LogEvent(Message)
  2.      'Open an error message log and append the message to it
  3.      Dim LogFileName
  4.      LogFileName = "/log/" & Replace(Request.ServerVariables("URL"), "/", "_") & ".log"
  5.      
  6.      Dim FO, OutFile
  7.      On Error Resume Next 'Will catch will IsObject()
  8.      Set FO = Server.CreateObject("Scripting.FileSystemObject")
  9.      If IsObject(FO) Then
  10.           Set OutFile = FO.OpenTextFile(Server.MapPath(LogFileName), 8, True)
  11.           If IsObject(OutFile) Then
  12.                OutFile.WriteLine(FormatDateTime(Now,2) & vbTab & FormatDateTime(Now,3) & vbTab & Message)
  13.                OutFile.Close
  14.                Set OutFile = Nothing
  15.           Else
  16.                'Could not create OutFile
  17.                If gDEBUG Then Response.Write "<BR>ERROR: In LogEvent(): Could Not create OutFile. LogFileName = " & LogFileName & " Maps to " & Server.MapPath(LogFileName) & vbCrLf
  18.           End If
  19.           Set FO = Nothing 'Close the object
  20.      Else
  21.           'Could not create FO
  22.           If gDEBUG Then Response.Write "<BR>ERROR: In LogEvent(): Could Not create FO." & vbCrLf
  23.      End If
  24.      On Error Goto 0
  25.      'If gDEBUG And Response.Buffer Then Response.Flush 'Write out any messages to the output stream.
  26. End Sub

Copy & Paste


Comments


There are currently no comments for this snippet. Be the first to comment!

Add comment


You must be registered and logged on to </dream.in.code> to leave comments.





Live ASP.NET Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

ASP.NET Tutorials

Reference Sheets

ASP.NET Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month