A good exception reporting class was found, with the extension method above. Net 3.5 used,
The solution is to send an email report when an exception occurs.
Using system;
Using system. Collections. Generic;
Using system. LINQ;
Using system. Web;
Using system. net. mail;
Namespace experiement
{
Public static class myextension
{
Public static void senderroremail (this exception ex)
{
Mailmessage = new mailmessage (New mailaddress ("from@gmail.com ")
, New mailaddress ("to@gmail.com "));
Mailmessage. Subject = "exception occured in your site ";
Mailmessage. isbodyhtml = true;
System. Text. stringbuilder errormessage = new system. Text. stringbuilder ();
Errormessage. appendline (string. Format ("<B> {0} </B >:{ 1}", "exception", Ex. Message ));
Errormessage. appendline (string. Format ("<B> {0} </B >:{ 1}", "stack trace", Ex. stacktrace ));
If (ex. innerexception! = NULL)
{
Errormessage. appendline (string. Format ("<B> {0} </B >:{ 1}", "inner exception", Ex. innerexception. Message ));
Errormessage. appendline (string. Format ("<B> {0} </B >:{ 1}", "inner stack trace", Ex. innerexception. stacktrace ));
}
Mailmessage. Body = errormessage. tostring ();
System. net. networkcredential networkcredentials = new
System. net. networkcredential ("youraccount@gmail.com", "password ");
Smtpclient = new smtpclient ();
Smtpclient. enablessl = true;
Smtpclient. usedefadefacredentials = false;
Smtpclient. Credentials = networkcredentials;
Smtpclient. Host = "smtp.gmail.com ";
Smtpclient. Port = 587;
Smtpclient. Send (mailmessage );
}
}
}
Usage:
Using system;
Namespace experiement
{
Public partial class webform1: system. Web. UI. Page
{
Protected void page_load (Object sender, system. eventargs E)
{
Try
{
Throw new exception ("My custom exception ");
}
Catch (exception ex)
{
Ex. senderroremail ();
Response. Write (ex. Message );
}
}
}
}