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 inforcesolutions.com", "wes AT inforcesolutions.com", "Web Application Error", err);
            System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient();
            smtp.Send(msg);
        }
        catch (Exception exMail) {
        }
    }
 
 

About wesmacdonald

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:

WordPress.com Logo

You are commenting using your WordPress.com 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: