Am currently using mvc4 with vs2012 and i installed mvc.elmah nugget and am done.
What i did ?
Initially i didnt write any code and my exception were logged in ELMAH.
Later i decided to use MVC HandleError to handle Application Exceptions and added filter
filters.Add(new HandleErrorAttribute());
Now i debugged in filters and see i have 2 filters one for ELMAH HandleErrorAttribute and MVC HandleErrorAttribute !
I saw this excellent link https://stackoverflow.com/a/5936867/1481690 which talks about using ErrorSignal to handle Application Exceptions
But am not using ErrorSignal
but still my Exceptions are captured by ELMAH ?
If i use
if (context.ExceptionHandled)
ErrorSignal.FromCurrentContext().Raise(context.Exception);
My Exceptions are logged twice.
My Question as follows
- Do i need to use 2 filters(ELMAH and MVC) ?
- If ELMAH is already having HandleErrorAttribute and log exception. Do i need to add MVC HandleErrorAttribute ?
What am doing currently is
Added filters
filters.Add(new HandleErrorAttribute());
and overriding (To handle Ajax Error in future)
public class HandleErrorAttribute : System.Web.Mvc.HandleErrorAttribute
{
public override void OnException(ExceptionContext context)
{
base.OnException(context);
}
Is this enough or what is the good practise ? Am not raising ErrorSignal as it is logging twice.
Am not using any try.catch
as am using below line and hope my exception is handled.
base.OnException(context);
}
Just want to make sure that am on right way !
Thanks for the time