前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Core + Vue 后台管理基础框架6——业务日志

Core + Vue 后台管理基础框架6——业务日志

作者头像
guokun
发布2020-09-03 15:52:20
3990
发布2020-09-03 15:52:20
举报
文章被收录于专栏:销声匿迹销声匿迹

1、前言

  上一篇,我们讲了审计日志,重点是重点业务表的审计字段。还有一种系统审计,就是重点业务对象的改动记录,是以审计日志表中的记录形式存在的。这种审计记录一般需要精确定位到某个终结点,最合适的实现方式就是操作过滤器。

2、实现

  自定义操作过滤器:

代码语言:javascript
复制
public class LogAttribute : ActionFilterAttribute
    {
        public string LogName { get; private set; }

        public LogAttribute(string logName)
        {
            this.LogName = logName;
        }

        public override async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next)
        {
            await base.OnActionExecutionAsync(context, next);

            var user = context.HttpContext.RequestServices.GetService<CurrentUser>();
            var log = new SysOperationLogDto
            {
                ClassName = context.Controller.ToString(),
                CreateTime = DateTime.Now,
                LogName = this.LogName,
                LogType = "业务日志",
                Method = ((Controllers.ControllerActionDescriptor)context.ActionDescriptor).ActionName,
                Message = JsonSerializer.Serialize(context.ActionArguments),
                Succeed = "成功",
                UserId = user.ID
            };

            var logService = context.HttpContext.RequestServices.GetService<ILogService>();
            await logService.AppendOperationLog(log);
        }
    }

  基本思路很简单,调用控制器终结点方法时,记录操作日志,操作日志中主要包含控制器名称,方法名称,调用入参等信息。

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2020-03-21 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档