예제 #1
0
        /// <summary>
        /// 记录异常日志
        /// </summary>
        /// <param name="log">异常日志</param>
        /// <returns>日志Id</returns>
        public Guid Write(ExceptionLog log)
        {
            //01.构造sql语句
            StringBuilder sqlBuilder = new StringBuilder();

            sqlBuilder.Append("SET @NEWID = UUID(); ");
            sqlBuilder.Append(
                "INSERT INTO ExceptionLogs (Id, Namespace, ClassName, MethodName, MethodType, ArgsJson, ExceptionType, ExceptionMessage, ExceptionInfo, InnerException, OccurredTime, IPAddress) VALUES (@NEWID, @Namespace, @ClassName, @MethodName, @MethodType, @ArgsJson, @ExceptionType, @ExceptionMessage, @ExceptionInfo, @InnerException, @OccurredTime, @IPAddress); ");
            sqlBuilder.Append("SELECT @NEWID; ");

            //02.初始化参数
            IDbDataParameter[] parameters =
            {
                new MySqlParameter("@Namespace",        log.Namespace.ToDbValue()),
                new MySqlParameter("@ClassName",        log.ClassName.ToDbValue()),
                new MySqlParameter("@MethodName",       log.MethodName.ToDbValue()),
                new MySqlParameter("@MethodType",       log.MethodType.ToDbValue()),
                new MySqlParameter("@ArgsJson",         log.ArgsJson.ToDbValue()),
                new MySqlParameter("@ExceptionType",    log.ExceptionType.ToDbValue()),
                new MySqlParameter("@ExceptionMessage", log.ExceptionMessage.ToDbValue()),
                new MySqlParameter("@ExceptionInfo",    log.ExceptionInfo.ToDbValue()),
                new MySqlParameter("@InnerException",   log.InnerException.ToDbValue()),
                new MySqlParameter("@OccurredTime",     log.OccurredTime.ToDbValue()),
                new MySqlParameter("@IPAddress",        log.IPAddress.ToDbValue())
            };

            //03.执行sql
            object result = _SqlHelper.ExecuteScalar(sqlBuilder.ToString(), parameters);
            Guid   newId  = Guid.Parse(result.ToString());

            return(newId);
        }
예제 #2
0
        /// <summary>
        /// 获取异常日志记录条数
        /// </summary>
        /// <param name="logId">日志Id</param>
        /// <param name="startTime">开始时间</param>
        /// <param name="endTime">结束时间</param>
        /// <returns>异常日志记录条数</returns>
        public int Count(Guid?logId, DateTime?startTime, DateTime?endTime)
        {
            string sql = "SELECT COUNT(*) FROM ExceptionLogs WHERE 0 = 0";

            #region # 条件过滤

            if (logId.HasValue)
            {
                sql = $"{sql} AND Id = '{logId.Value}'";
            }
            if (startTime.HasValue)
            {
                sql = $"{sql} AND OccurredTime >= '{startTime.Value}'";
            }
            if (endTime.HasValue)
            {
                sql = $"{sql} AND OccurredTime <= '{endTime.Value}'";
            }

            #endregion

            object result = _MySqlHelper.ExecuteScalar(sql);
            int    count  = Convert.ToInt32(result);
            return(count);
        }