码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2016-07-05 20:48:23      阅读:188      评论:0      收藏:0      [点我收藏+]

标签:

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

技术分享

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

技术分享

    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);
        }
    }

使用方法:

技术分享

我们就可以通过 功能信息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 操作日志之数据日志 控制增强

标签:

原文地址:http://www.cnblogs.com/shiningrise/p/osharp_DataLogging.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!