public async Task OnActionExecutionAsync(ActionExecutingContext filterContext, ActionExecutionDelegate next) { try { ActionControllerLog actionController = new ActionControllerLog(); actionController.DisplayName = filterContext.ActionDescriptor.DisplayName; actionController.ControllerName = (string)filterContext.RouteData.Values["Controller"]; actionController.ActionName = (string)filterContext.RouteData.Values["Action"]; actionController.UserName = "******"; actionController.CreatedDate = DateTime.Now; actionController.IsActive = true; await _logService.CreateActionControllerLog(actionController); if (!filterContext.ModelState.IsValid) { filterContext.Result = new BadRequestObjectResult(filterContext.ModelState); } } catch { } await next(); // logic after the action goes here }
public async Task CreateActionControllerLog(ActionControllerLog actionController) { try { actionController.IsActive = true; _dbContext.Add(actionController); await _dbContext.SaveChangesAsync(); } catch (Exception ex) { // while logging if there is a trouble, don't interrupt the process of app. } }