The global.asax class uses the Application_Error method to capture errors. Using System.Web.Mail, a webmaster can email themselves every time an error occurs.
The following code snippets demonstrates this technique.
[ C# ]
protected void Application_Error(Object sender, EventArgs e)
{
Exception ex = Server.GetLastError();
EmailException( ex );
}
private void EmailException( Exception ex )
{
MailMessage mail = new MailMessage();
mail.To = "me@mycompany.com";
mail.From = "you@yourcompany.com";
mail.Subject = "An exception occurred.";
mail.Body = ex.ToString();
SmtpMail.SmtpServer = "localhost"; //your real server goes here
SmtpMail.Send( mail );
}
[ VB.NET ]
Protected Sub Application_Error(sender As [Object], e As EventArgs)
Dim ex As Exception = Server.GetLastError()
EmailException(ex)
End Sub 'Application_Error
Private Sub EmailException(ex As Exception)
Dim mail As New MailMessage()
mail.To = "me@mycompany.com"
mail.From = "you@yourcompany.com"
mail.Subject = "An exception occurred."
mail.Body = ex.ToString()
SmtpMail.SmtpServer = "localhost" 'your real server goes here
SmtpMail.Send(mail)
End Sub 'EmailException