I have an ASP.NET MVC site running on .NET 4.0 that I am trying to set up error logging.
I found the Elmah.MVC NuGet package (v2.1.1, Elmah core: v1.2.1) and after this tutorial , to configure it, (did not do Step5 - javascript error logging)
It works correctly and sends me an email and logs 404 errors, but when I enter some html in the input <h1>Test</h1>to see how the site is processed, I get an HttpRequestValidationException, which is good in the sense that it will not let them throw it in and I have a page setup with an error that will be displayed when the site is published, but Elmah does not register information about this error.
I looked at this SO post and Elmah issue 217 says that it was resolved.
This is my ElmahHandleErrorAttribute class:
public class ElmahHandleErrorAttribute : System.Web.Mvc.HandleErrorAttribute
{
public override void OnException(ExceptionContext context)
{
base.OnException(context);
var e = context.Exception;
if (!context.ExceptionHandled
|| RaiseErrorSignal(e)
|| IsFiltered(context))
return;
LogException(e);
}
private static bool RaiseErrorSignal(Exception e)
{
var context = HttpContext.Current;
if (context == null)
return false;
var signal = ErrorSignal.FromContext(context);
if (signal == null)
return false;
signal.Raise(e, context);
return true;
}
private static bool IsFiltered(ExceptionContext context)
{
var config = context.HttpContext.GetSection("elmah/errorFilter")
as ErrorFilterConfiguration;
if (config == null)
return false;
var testContext = new ErrorFilterModule.AssertionHelperContext(
context.Exception, HttpContext.Current);
return config.Assertion.Test(testContext);
}
private static void LogException(Exception e)
{
var context = HttpContext.Current;
ErrorLog.GetDefault(context).Log(new Error(e, context));
}
}
What I indicated in my FilterConfig.cs:
public static void RegisterGlobalFilters(GlobalFilterCollection filters)
{
filters.Add(new ElmahHandleErrorAttribute());
filters.Add(new HandleErrorAttribute());
}
Is there a known workaround so that I can log Elmah email data about these kinds of errors?
thank.
source
share