osharp3 操作日志之数据日志 控制增强

osharp3 原来的数据日志,有配置文件中有这总开关,DataLoggingEnabled,原来的程序是,这个总开关关了,就无法记录数据日志了,,如果开了,,他不管记录不记录数据日志,系统都会存数据改动日志到DataLogCache中

ZPGE2CX24[XW%Q5SB4K(5[0

我在 DbContextBase中注入了一个操作记录员类 public IOperateLoger OperateLoger { get; set; }

image

    public class OperateLoger : IOperateLoger,IScopeDependency
    {
        public IOperateLogWriter LogWriter { get;private set; }
        /// <summary>
        /// 获取或设置 操作人信息
        /// </summary>
        public IOperator Operator { get; private set; }

        public IDataLogCache DataLogCache { get;private set; }

        public OperateLoger(IOperator @operator, IOperateLogWriter operateLogWriter, IDataLogCache dataLogCache)
        {
            Operator = @operator;
            LogWriter = operateLogWriter;
            DataLogCache = dataLogCache;
        }

        public FunctionInfo FunctionInfo { get; set; }
        public OperationResult OperationResult { get; set; }

        public bool DataLogEnabled {
            get { return FunctionInfo == null?false:FunctionInfo.DataLogEnabled; }
        }

        public void SaveLog()
        {
            if(FunctionInfo.OperateLogEnabled == false)
                return;
            var log = new OperateLog();
            log.Id = CombHelper.NewComb();
            log.CreatedTime = DateTime.Now;
            log.OperatorInfo.UserName = Operator.UserName;
            log.OperatorInfo.UserId = Operator.UserId;
            log.FunctionName = FunctionInfo.ModuleName + FunctionInfo.PowerName;
            log.OperationResult = OperationResult;
            if (FunctionInfo.DataLogEnabled)
            {
                foreach (var dataLog in DataLogCache.DataLogs)
                {
                    log.DataLogs.Add(dataLog);
                }
            }
            LogWriter.Write(log);
        }
    }

使用方法:

image

我们就可以通过 功能信息dto 来控制是否记录操作日志,,针对性比较强

    public class FunctionInfo
    {
        /// <summary>
        ///权限标记
        /// </summary>
        [Required, StringLength(50)]
        public string PowerCode { get; set; }

        /// <summary>
        ///权限名称
        /// </summary>
        [Required, StringLength(50)]
        public string PowerName { get; set; }

        /// <summary>
        ///模块标记
        /// </summary>
        [Required, StringLength(50)]
        public string PageCode { get; set; }//

        /// <summary>
        ///模块名称
        /// </summary>
        [Required, StringLength(50)]
        public string ModuleName { get; set; }

        /// <summary>
        /// 获取或设置 是否启用操作日志
        /// </summary>
        public bool OperateLogEnabled { get; set; }

        /// <summary>
        /// 获取或设置 是否启用数据日志
        /// </summary>
        public bool DataLogEnabled { get; set; }
    }
相关链接:
 
附加说明:osharp3的操作日志功能
 
 数据日志的开头,还可以在实体信息记录EntityInfo上控制
配置那开了DataLoggingEnabled,可以针对某个实体在EntityInfo关闭
功能信息Function上也有操作日志和数据日志的日志开关
posted @ 2016-07-05 19:45  shiningrise  阅读(519)  评论(0编辑  收藏  举报
// 侧边栏目录 // https://blog-static.cnblogs.com/files/douzujun/marvin.nav.my1502.css