'Enable logging for a classic asp site
I inherited a classic ASP project and and have deployed it on a IIS 7.5. I am able to access the site, however at certain point I get a generic 500 error page. I want to know what is going on, so I think the best is to see the logs
- Have found nothing in c:\WINDOWS\system32\LogFiles\ nor c:\inetpub\logs\
- Tried to enable logging as here: https://technet.microsoft.com/en-us/library/cc732826(v=ws.10).aspx But I have no Logging icon/button there (see screenshot).
- Tries custom error 500 page as here: http://www.iis.net/configreference/system.webserver/httperrors/error but there's no "Error Pages" icon (see screenshot)
- Tried to custom 500 page with web.config as here: http://blogs.iis.net/rickbarber/archive/2013/02/18/working-past-500-internal-server-error.aspx but seems that it gets ignored

For the record, I am a newbie with IIS/ASP so the question can sound a bit silly.. Thanks for any suggestion!
Solution 1:[1]
This will write the error info to the screen. Modify the "If blnLogFailure" section if you want to write to a file.
On Error Resume Next
Set objASPError = Server.GetLastError
blnLogFailure = TRUE
myMessage = "ERROR IN PROCESSING: " & objASPError.File & vbCrLf
myMessage = myMessage & "ASP Code: " & objASPError.ASPCode & vbCrLf
myMessage = myMessage & "Number: " & objASPError.Number & vbCrLf
myMessage = myMessage & "Source: " & objASPError.Source & vbCrLf
myMessage = myMessage & "Line Number: " & objASPError.Line & vbCrLf
myMessage = myMessage & "Description: " & objASPError.Description & vbCrLf
myMessage = myMessage & "ASP Description: " & objASPError.ASPDescription & vbCrLf
for each item in Request.ServerVariables
myMessage = myMessage & "ITEM: " & item & " VALUE: " & Request.ServerVariables(item) & vbCrLf
next
If blnLogFailure Then
Response.Write myMessage
End If
Solution 2:[2]
About actually logging Asp errors wherever they happen, as the question title seems to ask, a custom error page should be added.
This requires "HTTP Errors", so first install it if not already done. See Keith answer.
Then, add an .asp error page. This page has to be as robust as possible, with minimal dependencies. If it fails too, you will not have any log.
This page could first do something like:
Dim error
Set error = Server.GetLastError
LogErrorToFile
Sub LogErrorToFile()
Dim logFso
Dim log
On Error Resume Next
Set logFso = Server.CreateObject("Scripting.FileSystemObject")
If error.Number <> 0 Then
Exit Sub
End If
Set log = logFso.OpenTextFile("YourLogPath.txt", 8, True)
If error.Number <> 0 Then
Exit Sub
End If
log.WriteLine "URL: " & Request.ServerVariables("URL")
log.WriteLine "File: " & error.File
log.WriteLine "Line, col: " & error.Line & ", " & error.Column
log.WriteLine "Description" & error.Description & vbCrLf
log.Close
End Sub
Then add in this page whatever you wish.
The object returned by GetLastError is documented here.
Next, ask your site to use this error page in case of Asp errors. For this, set the 500,100 error page to your error page. In web.config, assuming your error file is named err500.asp and lies at the root of your site, this can be done with:
<system.webServer>
<httpErrors errorMode="DetailedLocalOnly">
<remove statusCode="500" subStatusCode="100" />
<!-- subStatusCode="100" are ASP errors -->
<error statusCode="500" subStatusCode="100" path="/err500.asp" responseMode="ExecuteURL" />
</httpErrors>
</system.webServer>
This answer is a simplification of this blog post. The sample code on this blog post is more complete and handles a log to database.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Jen R |
| Solution 2 |
