Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>After reading Dupin's comments it seems logical that it isn't quite possible. I tried digging around the Elmah source code and came up with a couple of alternatives that might be worth sharing.</p> <p>The obvious alternative is stick with my original option of using the Logged event:</p> <pre><code>void ErrorLog_Logged(object sender, ErrorLoggedEventArgs args) { string sessionId = Session.SessionID; Session["ElmahId_" + sessionId] = args.Entry.Id; } </code></pre> <p>For a more direct solution it is possible to manually log the error with the following:</p> <pre><code>string errorId = Elmah.ErrorLog.GetDefault(HttpContext.Current) .Log(new Elmah.Error(filterContext.Exception)); </code></pre> <p>However, using this approach won't hit your filters or mail module and so on.</p> <p>After doing a bit of thinking and a little more searching, I came up with a new compromise. Still using the logged event but I've found a way to create a new unique key that can be passed to the view, by adding my own data to the exception.</p> <pre><code>string loggingKey = "ElmahId_" + Guid.NewGuid().ToString(); filterContext.Exception.Data.Add("LoggingKey", loggingKey); </code></pre> <p>This way I can pass the exception in my view model, which has this key value in the Data collection. The logged event would be changed to something like this:</p> <pre><code>void ErrorLog_Logged(object sender, ErrorLoggedEventArgs args) { string key = args.Entry.Error.Exception.Data["LoggingKey"].ToString(); Session[key] = args.Entry.Id; } </code></pre> <p>Then in the view I get the key from the model to then pull the Id from the Session collection.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload