Beispiel #1
0
 private T Do <T>(Func <IDatabase, T> func)
 {
     try
     {
         var database = _conn.GetDatabase(DbNum);
         return(func(database));
     }
     catch (Exception ex)
     {
         LessExceptionLog.Submit("操作Redis异常:", ex.Message);
         return(default(T));
     }
 }
Beispiel #2
0
        public void ErrorTest()
        {
            string tagName = "异常标签";//自定义标签
            var    data    = new ExcDataParam()
            {
                Name = "请求参数", Data = new { Id = 001, Name = "张三" }
            };                                                                                    //自定义单个model
            var user = new ExcUserParam()
            {
                Id = "No0001", Name = "李廷礼", Email = "*****@*****.**", Description = "菁鲤汇高级开发工程师"
            };                                    //用户信息
            var datas = new List <ExcDataParam>() //自定义列表数据
            {
                new ExcDataParam()
                {
                    Name = "请求参数",
                    Data = new { Id = 002, Name = "李四" }
                },
                new ExcDataParam()
                {
                    Name = "返回结果",
                    Data = new { Id = 003, Name = "王五" }
                }
            };

            try
            {
                LessExceptionLog.Submit("不带参数");
                LessExceptionLog.Submit("带标签", tagName);
                LessExceptionLog.Submit("带用户&标签", user, tagName);
                LessExceptionLog.Submit("带自定义数据&标签", data, tagName);
                LessExceptionLog.Submit("带自定义数据&标签", datas, tagName);
                LessExceptionLog.Submit("带用户&自定义数据&标签", user, data, tagName);
                LessExceptionLog.Submit("带用户&自定义数据&标签", user, datas, tagName);

                //程序逻辑异常测试,用过try catch 捕获
                int number  = 0;
                int nubemr1 = 1 / number;
            }
            catch (Exception ex)
            {
                //注意:同一个异常ExceptionsLess只会提交一次,這就说明第二次提交则会无效
                //ex.Submit();//不带任何参数
                //ex.Submit(tagName);//带标签
                //ex.Submit(user, tagName);//带用户&标签
                //ex.Submit(data, tagName);//带自定义数据&标签
                //ex.Submit(datas, tagName);//带自定义数据&标签
                //ex.Submit(user, data, tagName);//带用户&自定义数据&标签
                ex.Submit(user, datas, tagName);//带用户&自定义数据&标签
            }
        }