Monday, February 27, 2006

Caveats about System.Diagnostics.StackTrace

This is a good site:

While I'm looking into self reporting of stack tracing of line from my framework, so that I can easily trace back to the line w/o throwing out unfriendly error message to surfer, use the stack trace class! .NET Rocks!

This is the codes I'ved used:
Dim sbMessage As New Text.StringBuilder
sbMessage.AppendFormat("Originating Host:{0}" & vbCrLf, System.Web.HttpContext.Current.Server.MachineName)
sbMessage.AppendFormat("User Host: {0}({1})" & vbCrLf, System.Web.HttpContext.Current.Request.UserHostName, System.Web.HttpContext.Current.Request.UserHostAddress)
sbMessage.AppendFormat("RawUrl : {0}" & vbCrLf, System.Web.HttpContext.Current.Request.RawUrl)
sbMessage.Append("Stack Trace:" & vbCrLf)
Dim st As New StackTrace(True)
For Each stEntry As StackFrame In st.GetFrames
sbMessage.Append(stEntry.ToString & vbCrLf)

Subsequently, send it to your mailbox using System.Net.Mail.SmtpClient(), and you've got your own error reporting machanism.

No comments: