I'm using the customErrors attribute of the web.config file to present custom errors pages:
<customErrors mode="On" defaultRedirect="/errorpage.aspx">
<error statusCode="404" redirect="/404Page.aspx"/>
<error statusCode="403" redirect="/403page.aspx"/>
</customErrors>
Nothing too fancy. Now what I want to do is log the error that occurs when any of these pages are loaded. I'm specifically interested in any exceptions, I don't really care what page the user was on when they got a 404.
I'd like to capture the exception and record it into a db Table. Will something like this work:
//errorpage.aspx
public void Page_Load(object sender,EventArgs e)
{
Exception objErr = Server.GetLastError().GetBaseException();
var err = new {Url = Request.Url.ToString(),
Message = objErr.Message,
Trace = objErr.StackTrace.ToString()};
db.Errors.InsertOnSubmit(err);
db.SubmitChanges();
Server.ClearError();
}
Is there any other information that is worth capturing, or is generally captured on an error?