Пример #1
0
        /// <summary>
        /// 构造方法
        /// </summary>
        public RedisCacheManager()
        {
            string redisConfiguration = ComHelper.GetConf("AppSettings:RedisCachingAOP:ConnectionString");//获取连接字符串

            if (string.IsNullOrWhiteSpace(redisConfiguration))
            {
                throw new ArgumentException("redis config is empty", nameof(redisConfiguration));
            }

            this.redisConnenctionString = redisConfiguration;
            this.redisConnection        = GetRedisConnection();
        }
Пример #2
0
        /// <summary>
        /// 初始化数据库上下文
        /// </summary>
        /// <param name="isAutoClose"></param>
        private void InitDbContext(bool isAutoClose)
        {
            if (string.IsNullOrEmpty(ConnectionString))
            {
                throw new ArgumentNullException("数据库连接字符串为空");
            }

            Db = new SqlSugarClient(new ConnectionConfig()
            {
                ConnectionString          = ConnectionString,
                DbType                    = DbType,
                IsAutoCloseConnection     = isAutoClose,
                IsShardSameThread         = false,
                InitKeyType               = InitKeyType.Attribute,
                ConfigureExternalServices = new ConfigureExternalServices()
                {
                    //DataInfoCacheService = new HttpRuntimeCache()
                },
                MoreSettings = new ConnMoreSettings()
                {
                    //IsWithNoLockQuery = true,
                    IsAutoRemoveDataCache = true
                },
            });

            if (ComHelper.GetConf("AppSettings:SqlAOP:Enabled").ObjToBool())
            {
                Db.Aop.OnLogExecuting = (sql, pars) => //SQL执行中事件
                {
                    Parallel.For(0, 1, e =>
                    {
                        var paras = GetParas(pars);
                        var msg   = $"执行SQL:{paras}   【SQL语句】:{sql}";

                        MiniProfiler.Current.CustomTiming("SQL", msg);
                        //LogLock.OutSql2Log("SqlLog", new string[] { GetParas(pars), "【SQL语句】:" + sql });
                        _loggerHelper.SqlLog(msg);
                    });
                };
            }
        }