Exemplo n.º 1
0
        /// <summary>
        /// 记录异常日志
        /// </summary>
        /// <param name="log">异常日志</param>
        /// <returns>日志Id</returns>
        public Guid Write(ExceptionLog log)
        {
            //生成GUID
            string generateIdSql = "SELECT GEN_UUID() FROM rdb$database;";
            object result        = _SqlHelper.ExecuteScalar(generateIdSql);
            Guid   serialSeedId  = Guid.Parse(result.ToString());

            //01.构造sql语句
            StringBuilder sqlBuilder = new StringBuilder();

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

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

            //03.执行sql
            _SqlHelper.ExecuteNonQuery(sqlBuilder.ToString(), parameters);
            return(serialSeedId);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 创建序列种子
        /// </summary>
        /// <param name="serialSeed">序列种子</param>
        public void Create(SerialSeed serialSeed)
        {
            string generateIdSql = "SELECT GEN_UUID() FROM rdb$database;";
            object result        = _SqlHelper.ExecuteScalar(generateIdSql);
            Guid   serialSeedId  = Guid.Parse(result.ToString());

            StringBuilder sqlBuilder = new StringBuilder();

            sqlBuilder.Append("INSERT INTO \"SerialSeeds\" ");
            sqlBuilder.Append("	(\"Id\", \"Name\", \"Prefix\", \"Timestamp\", \"SerialLength\", \"TodayCount\", \"Description\") ");
            sqlBuilder.Append("VALUES ");
            sqlBuilder.Append("	(@Id, @Name, @Prefix, @Timestamp, @SerialLength, @TodayCount, @Description); ");

            IDbDataParameter[] parameters =
            {
                new FbParameter("@Id",           serialSeedId.ToDbValue()),
                new FbParameter("@Name",         serialSeed.Name.ToDbValue()),
                new FbParameter("@Prefix",       serialSeed.Prefix.ToDbValue()),
                new FbParameter("@Timestamp",    serialSeed.Timestamp.ToDbValue()),
                new FbParameter("@SerialLength", serialSeed.SerialLength.ToDbValue()),
                new FbParameter("@TodayCount",   serialSeed.TodayCount.ToDbValue()),
                new FbParameter("@Description",  serialSeed.Description.ToDbValue())
            };

            _SqlHelper.ExecuteNonQuery(sqlBuilder.ToString(), parameters);
            serialSeed.Id = serialSeedId;
        }
Exemplo n.º 3
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 \"RunningLogs\" WHERE 0 = 0";

            #region # 条件过滤

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

            #endregion

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