asp.net - MVC [HandleError] HandleErrorAttribute called twice when using global logging -
In an MVC3 web application, I was using
Public Static Zero Global Filter Filter (GlobalFilterCollection filter)
In order to implement global error handling, where the user was shown 'Error' view, if there was no exception, an exception occurred.
For a particular view, I also wanted to display a different error view, if by decorating the method with [HandleError (View = "SpecialError")] Unwanted exceptions occurred. It works fine.
Then I want to add global logging to unsociable exceptions. I created a custom handle error feature with the logging code:
Public class MyHandleErrorAttribute: HandleErrorAttribute {The public override zero over exponence (exception context context) {// code to log code code. Xxation (reference); }}
And instead of using this attribute name, register global filter and method decoration has been updated. It usually works, but when there is an exception method that is decorated with MyHandleError (see = "special error")] , then the expression method It is said twice that I originally believed that the method of decorating with this feature led to the global handler, but it seems that it is added to the bus (which is more understandable) , But this is not my wish). By calling twice on the eclipse, the same exception is logged twice, which should not be so. I do not think the expression is being called twice because because is a custom feature - I believe this standard handle also happens with the error feature, it looks like it still looks like I I am recording this. / P> Eventually, I want to log all the handled exceptions (once), while maintaining the features offered by [handler], especially for the special method exceptions, different view sets do. Is there a clean way to do this?
I believe that I have found a clean solution of myself, expanding the handles is a good It seemed like a thought but now I feel that it was a step in the wrong direction. I did not want to handle any type of errors separately, before logging only once to write an exception before HandleError raised them. Because of this, the default handle error can be dropped in place, however, adoption can be said many times, but it appears to be completely benign in standard implementation of HandleErrorAttribute.
Instead I have created an exception logging filter:
Public square logged expired filter: IExceptionFilter {public zero but exception (Exception contact filter filter)} {// Code log}}
Also it is not required to get the with filter properties because it is registered only once in the Register with Globefilter handraherty.
Public status Rick void RegisterGlobalFilters (GlobalFilterCollection Filters) {filters.Add (new logfest filter ()); Filter. Add (New Handler Attribute ()); }
This neatly logged in without changing the standard [HandleError] features
Comments
Post a Comment