Note that there are some explanatory texts on larger screens.

plurals
  1. POGetting the Id of an error in Elmah after calling .Raise()
    primarykey
    data
    text
    <p>I'm working on an MVC3 application and I'm using Elmah to handle my error logging. What I want in my application is to carry the Elmah Id onto the custom error page as I will provide a link which allows a user to specifically report it in the event that it is a repeat error (in their opinion).</p> <p>Now, I've read similar questions on here and they suggest adding the following code (or similar) to the Global.asax.cs file:</p> <pre><code>void ErrorLog_Logged(object sender, ErrorLoggedEventArgs args) { string sessionId = Session.SessionID; Session["ElmahId_" + sessionId] = args.Entry.Id; } </code></pre> <p>This is what I'm using at the moment, with the SessionID allowing for added flexibility in making the Session stored object unique. However, this may still cause issues if more than one error occurs at (virtually) the same time.</p> <p>Instead, I decided to work on my own HandleErrorAttribute that looks something like this:</p> <pre><code>public class ElmahHandleErrorAttribute : FilterAttribute, IExceptionFilter { public void OnException(ExceptionContext filterContext) { if (filterContext == null) throw new ArgumentNullException("filterContext"); if (filterContext.IsChildAction &amp;&amp; (!filterContext.ExceptionHandled &amp;&amp; filterContext.HttpContext.IsCustomErrorEnabled)) { Elmah.ErrorSignal.FromCurrentContext().Raise(filterContext.Exception); // get error id here string errorId = null; string areaName = (String)filterContext.RouteData.Values["area"]; string controllerName = (String)filterContext.RouteData.Values["controller"]; string actionName = (String)filterContext.RouteData.Values["action"]; var model = new ErrorDetail { Area = areaName, Controller = controllerName, Action = actionName, ErrorId = errorId, Exception = filterContext.Exception }; ViewResult result = new ViewResult { ViewName = "Error",, ViewData = new ViewDataDictionary&lt;ErrorDetail&gt;(model), TempData = filterContext.Controller.TempData }; filterContext.Result = result; filterContext.ExceptionHandled = true; filterContext.HttpContext.Response.Clear(); filterContext.HttpContext.Response.TrySkipIisCustomErrors = true; } } } </code></pre> <p>where ErrorDetail is a custom model which just has the public properties that are being set here as strings. This data can then be shown in the model for admin's at a quick glance and the errorId can be used to create the 'Report Error' link.</p> <p>So my question is does anyone know of a way of getting the Id after the line</p> <pre><code>Elmah.ErrorSignal.FromCurrentContext().Raise(filterContext.Exception) </code></pre> <p>without using the Logged event in the global.asax.cs?</p> <p>Any thoughts are much appreciated.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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