/// <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); }
/// <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; }
//Public #region # 删除运行日志 —— void RemoveRunningLogs(IEnumerable<Guid> ids) /// <summary> /// 删除运行日志 /// </summary> /// <param name="ids">运行日志Id集</param> public void RemoveRunningLogs(IEnumerable <Guid> ids) { #region # 验证 Guid[] specIds = ids == null ? new Guid[0] : ids.ToArray(); if (!specIds.Any()) { return; } #endregion string guids = specIds.FormatGuids(); string sql = $"DELETE FROM \"RunningLogs\" WHERE \"Id\" IN ({guids})"; _SqlHelper.ExecuteNonQuery(sql); }