Keep tabs on your site errors

Putting up a site on a remote server and placing your errors in the event log won’t do you much good so I opted to place some code in Global.asax Application_Error() to email me if something went horribly wrong. 
Here is what it looks like:
void Application_Error(Object sender, EventArgs e) {
        Exception ex = Server.GetLastError().GetBaseException();
        string err = "MESSAGE: " + ex.Message +
    "\nSOURCE: " + ex.Source +
    "\nFORM: " + Request.Form.ToString() +
    "\nQUERYSTRING: " + Request.QueryString.ToString() +
    "\nTARGETSITE: " + ex.TargetSite +
    "\nSTACKTRACE: " + ex.StackTrace;
        try {
            System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage("www AT", "wes AT", "Web Application Error", err);
            System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient();
        catch (Exception exMail) {

About Wes MacDonald

Wes MacDonald is a Visual Studio ALM MVP, PSD, MCT and a Principal Consultant for LIKE 10 INC., a SharePoint Server, Visual Studio and Team Foundation Server Consulting Firm providing premium support and guidance services.

No comments yet... Be the first to leave a reply!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: