NOTE: I know the various reasons to avoid using the session, but this is a project I\'ve inherited, so please skip that part of any replies :)
Since it\'s a solved probl
Rather than patching Elmah, I did this with Exception data. In Global.asax I inserted the extra data into the exception on Application_Error(). "HistoryStack" is my own class for recording user history, including button and tab clicks:
void Application_Error(object sender, EventArgs e)
{
Exception ex = Server.GetLastError().GetBaseException();
var stack = HistoryStack.Dump(); // essentially grabs data from the session
ex.Data.Add("historyStack", stack);
}
Then, in ErrorMail_Mailing() I grabbed the data back and appended it in the email:
void ErrorMail_Mailing(object sender, Elmah.ErrorMailEventArgs e)
{
var stack = e.Error.Exception.Data["historyStack"] as Stack;
if (stack == null && e.Error.Exception.InnerException != null)
{
// could probably skip the first try and go straight to this assignment:
stack = e.Error.Exception.InnerException.Data["historyStack"] as Stack;
}
if (stack != null && stack.Count > 0)
{
e.Mail.Body = e.Mail.Body + "Browsing History
" + System.Environment.NewLine;
while (stack.Count > 0)
{
e.Mail.Body = e.Mail.Body + stack.Pop() + "
" + System.Environment.NewLine;
}
}
}
Now this data is appended to the bottom of the email. No patches or extensions necessary.