Application Level Error Handling Question

C

Corey B

I have added code to my Application_Error sub in Global.ASAX so that
whenever an error occurs in my ASP.NET application - it sends me an
email with the error information. However the information that I am
receiving doesn't have everything I would like. It doesn't give the
exact line of code and the exact place where the error occurred. Can
anyone help me with the code? I would like it to send me the same type
of information that you would see on the screen when an error occurs.
Here is the code that I am using in my Application_Error sub: (VB)

******************************
Dim ex As Exception = Server.GetLastError.GetBaseException
Dim strMessage As String
strMessage = "MESSAGE: " & ex.Message & vbCrLf & _
"SOURCE: " & ex.Source & vbCrLf & _
"STACKTRACE: " & ex.StackTrace & vbCrLf & _
"TARGETSITE: " & ex.TargetSite.ToString & vbCrLf & _
"REMOTEIP: " & Request.UserHostAddress
******************************

Then it emails me the strMessage string. An example of the email that
I receive is below:

******************************
MESSAGE: Object reference not set to an instance of an object.

SOURCE: MyApp

STACKTRACE: at MyApp.testPage.Page_Load(Object sender, EventArgs e)
at System.EventHandler.Invoke(Object sender, EventArgs e)
at System.Web.UI.Control.OnLoad(EventArgs e)
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Page.ProcessRequestMain()

TARGETSITE: Void Page_Load(System.Object, System.EventArgs)

REMOTEIP: 127.0.0.1
******************************

The stacktrace is kind of helpful but it doesn't point me to a
particular line of code like a normal error message that you would see
on screen does.

Thanks,
Corey
 
K

Kevin Spencer

You would have to use a Debug build to get that information.

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

Hard work is a medication for which
there is no placebo.
 
I

ifrtuser

You would have to build it in Debug mode. The binary built using the
Debug mode contains line number and other information. It is best
practice not to run in Debug mode in production environment.
 
C

Corey B

Thanks for the confirmation. I did a little more searching and found
that indeed I need to build in Debug mode instead of Release mode to
get the line numbers.

Thanks,
Corey
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,001
Messages
2,570,254
Members
46,851
Latest member
CliftonCor

Latest Threads

Top