Public classBasecontroller:controller {/// <summary> ///called after the action method is invoked. /// </summary> /// <param name= "Filtercontext" >Information about the current request and action.</param> protected Override voidonactionexecuted (ActionExecutedContext filtercontext) {varServiceName =string. Empty; foreach(varValueinchfilterContext.RequestContext.RouteData.Values) {if(value.) Key.tolower () = ="Controller")//Get the current controller {servicename+ = value. Value.tostring () +"---"; } Else if(value.) Key.tolower () = ="Action")//Gets the current ActionName {servicename+=value. Value.tostring (); }} logwriter.debug (servicename); Base. OnActionExecuted (Filtercontext); } /// <summary> ///called when a unhandled exception occurs in the action. /// </summary> /// <param name= "Filtercontext" >Information about the current request and action.</param> protected Override voidonexception (Exceptioncontext filtercontext) {logwriter.error (FilterContext.Exception.Message, filt Ercontext.exception); Global Exception capture OutputBase. Onexception (Filtercontext); } }
MVC is better than bad writing---> Global exception capture and action capture