Exemplo n.º 1
0
        public async Task Hand(ActionExecutingContext context, ActionExecutionDelegate next)
        {
            var auditInfo = CreateAuditInfo(context);

            var sw = new Stopwatch();

            sw.Start();

            var resultContext = await next();

            sw.Stop();

            if (auditInfo != null)
            {
                try
                {
                    //执行结果
                    auditInfo.Result = JsonSerializer.Serialize(resultContext.Result);
                    //用时
                    auditInfo.ExecutionDuration = sw.ElapsedMilliseconds;

                    await _auditInfoService.Add(auditInfo);
                }
                catch (Exception ex)
                {
                    _logger.LogError("审计日志插入异常:{@ex}", ex);
                }
            }
        }
Exemplo n.º 2
0
        public async Task Hand(ActionExecutingContext context, ActionExecutionDelegate next)
        {
            var auditInfo = CreateAuditInfo(context);

            var sw = new Stopwatch();

            sw.Start();

            var resultContext = await next();

            sw.Stop();

            if (auditInfo != null)
            {
                try
                {
                    //执行结果
                    var str = (resultContext.Result as ObjectResult)?.Value.ToJson();
                    if (str != null)
                    {
                        auditInfo.Result = str.Length > 12000 ? str.Substring(0, 12000) : str;
                    }

                    //用时
                    auditInfo.ExecutionDuration = sw.ElapsedMilliseconds;

                    await _auditInfoService.Add(auditInfo);
                }
                catch (Exception ex)
                {
                    _logger.LogError("审计日志插入异常:{@ex}", ex);
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// 执行审计功能
        /// </summary>
        /// <param name="context"></param>
        /// <param name="next"></param>
        /// <returns></returns>
        private async Task ExecuteAuditing(ActionExecutingContext context, ActionExecutionDelegate next)
        {
            var auditInfo = CreateAuditInfo(context);

            var sw = new Stopwatch();

            sw.Start();

            var resultContext = await next();

            sw.Stop();

            //执行结果
            auditInfo.Result = JsonConvert.SerializeObject(resultContext.Result);
            //用时
            auditInfo.ExecutionDuration = sw.ElapsedMilliseconds;

            await _auditInfoService.Add(auditInfo);
        }
Exemplo n.º 4
0
        public async Task Hand(ActionExecutingContext context, ActionExecutionDelegate next)
        {
            var config = _configProvider.Get <AuthConfig>();

            if (!config.Auditing)
            {
                await next();

                return;
            }

            var auditInfo = CreateAuditInfo(context);

            var sw = new Stopwatch();

            sw.Start();

            var resultContext = await next();

            sw.Stop();

            if (auditInfo != null)
            {
                try
                {
                    //执行结果
                    if (resultContext.Result is ObjectResult result)
                    {
                        auditInfo.Result = JsonSerializer.Serialize(result.Value);
                    }

                    //用时
                    auditInfo.ExecutionDuration = sw.ElapsedMilliseconds;

                    await _auditInfoService.Add(auditInfo);
                }
                catch (Exception ex)
                {
                    _logger.LogError("审计日志插入异常:{@ex}", ex);
                }
            }
        }
Exemplo n.º 5
0
 public Task <IResultModel> Add(AuditInfoAddModel model)
 {
     return(_service.Add(model));
 }