标签:
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; } }
标签:
原文地址:http://www.cnblogs.com/shiningrise/p/osharp_DataLogging.html