After reading the comments, Dupin seems logical that this is not entirely possible. I tried digging into the Elmah source code and came up with a couple of alternatives that might be worth sharing.
An obvious alternative is to use my original option to use a registered event:
void ErrorLog_Logged(object sender, ErrorLoggedEventArgs args) { string sessionId = Session.SessionID; Session["ElmahId_" + sessionId] = args.Entry.Id; }
For a more direct solution, you can manually register an error with the following:
string errorId = Elmah.ErrorLog.GetDefault(HttpContext.Current) .Log(new Elmah.Error(filterContext.Exception));
However, using this approach will not result in blows to your filters or mail module, etc.
After a little thought and a bit more searching, I came up with a new compromise. Still using the registered event, but I found a way to create a new unique key that can be passed to the view by adding my own data to the exception.
string loggingKey = "ElmahId_" + Guid.NewGuid().ToString(); filterContext.Exception.Data.Add("LoggingKey", loggingKey);
That way, I can pass an exception in my view model, which has this key value in the data collection. The registered event will be changed to the following:
void ErrorLog_Logged(object sender, ErrorLoggedEventArgs args) { string key = args.Entry.Error.Exception.Data["LoggingKey"].ToString(); Session[key] = args.Entry.Id; }
Then, in the view, I get the key to the model, then to derive the identifier from the collection of sessions.
Adam goss
source share