I am doing this inside my BaseController. Something like that:
protected override void OnActionExecuted(ActionExecutedContext filterContext) { // If in Debug mode... if (filterContext.HttpContext.IsDebuggingEnabled) { var message = string.Format(CultureInfo.InvariantCulture, "Leaving {0}.{1} => {2}", filterContext.Controller.GetType().Name, filterContext.ActionDescriptor.ActionName.Trim(), filterContext.Result); Logger.Debug(message); } // Logs error no matter what if (filterContext.Exception != null) { var message = string.Format(CultureInfo.InvariantCulture, "Exception occured {0}.{1} => {2}", filterContext.Controller.GetType().Name, filterContext.ActionDescriptor.ActionName.Trim(), filterContext.Exception.Message); Logger.Error(message); } base.OnActionExecuted(filterContext); }
Hope you get this idea.
You can also register before the action is completed using:
protected override void OnActionExecuting(ActionExecutingContext filterContext)
source share