Tutorial :Error Logging: Source Error and Source File


When developing a .Net web application, if a run time error is generated, it shows some "extra" debug information that I can't find in the Exception class.

It shows a "Source Error" section which shows a code excerpt with line numbers showing exactly where the error was generated and it shows the "Source File", the actual page that threw the exception.

alt text http://i39.tinypic.com/2wfjszr.jpg

Can this information be gathered and logged programatically?

FYI I'm not using an error logging framework, the app simply captures errors in the Global.asax.cs file and writes the contents of the exception to a DB table. Maybe this is where I'm going wrong. Let me know if i'll need to adopt a framework to support quality logging.


You should take a look at the ELMAH project which will allow you to automatically capture and log all unhandled exceptions including recording the yellow screen of death.

For each error, as well as recording the YSOD, and stack trace it will also record the server variables too so you can see information such as http referrer, page requested, etc.

It can record exceptions in a various databases or xml files, and send you an email as they are logged. It can be integrated into a running .Net web application without changing a line of code, just adding entries to web.config

You can also log entries in the log programatically for when you want to catch the exception but still record it.

Full details are on the ELMAH website, and a getting started guide on the Elmah.io site.


ELMAH is very cool, drop-in, unhandled error logging component. It will even allow you to see the yellow screen of death (which includes the information you're after) as well as post data.


the page that threw the error should be in the Exception.StackTrace property


I'm not sure where the code-snippet you mention comes from though.

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »