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 Wes MacDonald

Wes MacDonald is a DevOps Consultant for LIKE 10 INC., a DevOps consulting firm providing premium support, guidance and services for Azure, Microsoft 365 and Azure DevOps.

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 )

Facebook photo

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

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: