示例#1
0
        public void OnActionExecuted(ActionExecutedContext filterContext)
        {
            var auditData = AbpAuditFilterData.GetOrNull(filterContext.HttpContext);

            if (auditData == null)
            {
                return;
            }

            auditData.Stopwatch.Stop();

            auditData.AuditInfo.ExecutionDuration = Convert.ToInt32(auditData.Stopwatch.Elapsed.TotalMilliseconds);
            auditData.AuditInfo.Exception         = filterContext.Exception;

            _auditingHelper.Save(auditData.AuditInfo);
        }
        public void OnActionExecuted(ActionExecutedContext filterContext)
        {
            var auditData = AbpAuditFilterData.GetOrNull(filterContext.HttpContext);

            if (auditData == null)
            {
                return;
            }

            auditData.Stopwatch.Stop();

            auditData.AuditInfo.ExecutionDuration = Convert.ToInt32(auditData.Stopwatch.Elapsed.TotalMilliseconds);
            auditData.AuditInfo.Exception         = filterContext.Exception;

            if (_auditingConfiguration.SaveReturnValues && filterContext.Result != null)
            {
                switch (filterContext.Result)
                {
                case AbpJsonResult abpJsonResult:
                    if (abpJsonResult.Data is AjaxResponse ajaxResponse)
                    {
                        auditData.AuditInfo.ReturnValue = _auditSerializer.Serialize(ajaxResponse.Result);
                    }
                    else
                    {
                        auditData.AuditInfo.ReturnValue = _auditSerializer.Serialize(abpJsonResult.Data);
                    }
                    break;

                case JsonResult jsonResult:
                    auditData.AuditInfo.ReturnValue = _auditSerializer.Serialize(jsonResult.Data);
                    break;

                case ContentResult contentResult:
                    auditData.AuditInfo.ReturnValue = contentResult.Content;
                    break;
                }
            }

            _auditingHelper.Save(auditData.AuditInfo);
        }