標籤:style blog io ar color os sp for on
public class BaseController : Controller { /// <summary> /// Called after the action method is invoked. /// </summary> /// <param name="filterContext">Information about the current request and action.</param> protected override void OnActionExecuted(ActionExecutedContext filterContext) { var servicename = string.Empty; foreach (var value in filterContext.RequestContext.RouteData.Values) { if (value.Key.ToLower() == "controller") //擷取當前的Controller { servicename += value.Value.ToString() + "---"; } else if (value.Key.ToLower() == "action")//擷取當前的ActionName { servicename += value.Value.ToString(); } } LogWriter.Debug(servicename); base.OnActionExecuted(filterContext); } /// <summary> /// Called when an unhandled exception occurs in the action. /// </summary> /// <param name="filterContext">Information about the current request and action.</param> protected override void OnException(ExceptionContext filterContext) { LogWriter.Error(filterContext.Exception.Message, filterContext.Exception); //全域異常捕獲輸出 base.OnException(filterContext); } }
MVC 好記星不如爛筆頭之 ---> 全域異常捕獲以及ACTION捕獲