It is important to know what is going on with your site in development and production. By implementing proper error logging, you can quickly track down errors, and provide your team members with enhanced error information. With the new ASP Error object you can create a simple and effective logging system.
ASP Error Object
Did I tell you I love the new ASP Error object? It finally enables developers to control page execution. This object is used to retrieve details of the last error that occurred within an ASP page. Combine that with the ability to create custom error pages, and you have a pretty powerful tool within the development shack.
The error object consists of nine properties; however, I will only mention the properties used within the demo.
ASPDescription - returns a description for all non-ASP errors. Category - the evil being, external object, or script that caused the error. Column - column position of the rogue character. Description - description of ASP error. File - the ASP file that caused the error. Line - the line number of the evil code. Source - the actual evil code that caused the error.
Why should I implement error logging?
In production, I create an agent that monitors the error table and notifies me via e-mail once an error occurs. If you are monitoring multiple sites, this can be extremely handy and useful. The detailed error information allows me to get to the root of the problem quickly.
The typical development staff usually has one or two master gurus monitoring several junior code warriors. The average day is usually spent helping them track-down simple coding errors. Well, what if you could give them a way to trace down the errors without bugging you every 30 minutes? This would definitely increase productivity within the development shack. The error.asp contains all the ASP error codes as well as a detailed description for each error. This page can be routinely updated to display fixes and things to try before running to the master gurus.
As a manager it is important to monitor the effectiveness of your staff. By logging errors you can track common mistakes and address them with a training class.
When you have 6 to 12 web developers it is a lot easier to query a table for information, than trying to drain it out of the new hire or freshly minted consultant. Besides, it really scares them when you call their extension and tell them the answer to the question that they were getting ready to ask you =).
How do I implement error logging?
Almost all ASP errors throw the "500 - Internal Server Error", we are going to replace this page with a custom asp script that logs information to a database. I usually create two versions of this file, one for development and another for production.
The steps below walk you through implementing this feature.
Step 1 - Create your table. I have included a SQL script to run against SQL Server.
Step 2 - Place the error.asp file on your server. Make sure you change the connection string information.
Step 3 - Right-click on the directory or site and select the properties option. Choose the custom errors tab.
Step 4 - Select the 500:100 HTTP Error and hit edit properties.
Step 5 - Change the message type to URL and point to error.asp.
Now lets cause some errors. Load the error_demo.asp file included with the demo, it should cause an error in a flash! You will then receive a well-formatted and very detailed error screen.
I hope this article has given you some ideas and insight into error logging. No matter what version of ASP you are using, the benefits are still the same. If you have any questions, comments, or problems my contact information is listed here.
For those of you who are interested, the demo files are available here for download.