This is what I do, and I still got a bug because of an email problem.
I never keep anything on the DB, cause if the DB has an error I will never have that error on the DB cause, logically, the insert will fail!
So I email to a special email address like [email protected]
Subject: [Application name] [Time Stamp: ddmmyyyy hhmmss]
Message: Application, Error Message, Stack Trace Information plus session variables like username and server variables like Referrer.
the best friend of an ASP.NET developer is the stack trace information, it is here that you will know what went wrong, what was the call and where it was calling.
the only problem that you have in this system, is that you will not get anything if the email has a problem (some exception when sending the email), and for that I started add to a monthly XML file [errorLog_ mmm_yyyy.xml] as well and made a simple "drag-and-drop" page with a gridview that loaded the XML for the month and year that I wanted to check the errors.
try
{
// production code
}
catch(Exception ex)
{
Utilities.Mail.SendError(ex);
}
or the best way: Add it to the Application_Error in global.asax:
<%@ Application Language="C#" %>
<%@ Import Namespace="System.Diagnostics" %>
<script language="C#" runat="server">
void Application_Error(object sender, EventArgs e)
{
//get reference to the source of the exception chain
Exception ex = Server.GetLastError().GetBaseException();
//log the details of the exception and page state to the
//Windows Event Log
EventLog.WriteEntry("myWebApplication name",
"MESSAGE: " + ex.Message +
"\nSOURCE: " + ex.Source +
"\nFORM: " + Request.Form.ToString() +
"\nQUERYSTRING: " + Request.QueryString.ToString() +
"\nTARGETSITE: " + ex.TargetSite +
"\nSTACKTRACE: " + ex.StackTrace,
EventLogEntryType.Error);
Utilities.Mail.SendError(ex);
}
</script>
with the code above you add the error to the event log, I append the error to the XML file in the SendError(Exception) function.