private void Save(int objId, int tryCount) { if (this.LogId > 0) { throw new Exception("日志 " + this.LogId + " 已保存过,不能再次保存"); } DateTime dtmLodId; lock (st_LogIdLock) { dtmLodId = st_LogIdLock.GetLogId(); } string strTableName = Tables.Log.GetTableName(dtmLodId); Database.DbConnection dbConnection = this.Application.GetDbConnection(); if (dbConnection.TableIsExist(strTableName) == false) { dbConnection.CreateTable(typeof(Tables.Log), strTableName); } string strConfig = null; System.Xml.XmlDocument xmlDoc = new System.Xml.XmlDocument(); System.Xml.XmlNode xnLogConfig = this.GetLogConfig(xmlDoc); if (xnLogConfig != null) { xmlDoc.AppendChild(xnLogConfig); strConfig = xmlDoc.OuterXml; } try { string strSql = dtmLodId.Ticks.ToString() + "," + Function.SqlStr(this.GetType().FullName, 250) + "," + objId + "," + Function.SqlStr(strConfig); strSql = "INSERT INTO " + strTableName + " (" + Tables.Log.LogId + "," + Tables.Log.LogType + "," + Tables.Log.ObjId + "," + Tables.Log.XMLConfig + ") VALUES (" + strSql + ")"; dbConnection.ExecuteNonQuery(strSql); this.m_LogId = dtmLodId.Ticks; } catch { if (tryCount > 3) { throw new Exception("保存日志 " + this.GetType().FullName + " 时发生错误,已重试3次。"); } else { this.Save(objId, tryCount + 1); } } finally { dbConnection.Close(); } }
private void Save(int tryCount) { if (this.LogId > 0) { throw new Exception("任务运行日志 " + this.LogId + " 已保存过,不能再次保存"); } DateTime dtmLodId = DateTime.Now; string strTableName = Tables.TaskLog.GetTableName(dtmLodId); Database.DbConnection dbConnection = this.Config.Application.GetDbConnection(); if (dbConnection.TableIsExist(strTableName) == false) { dbConnection.CreateTable(typeof(Tables.TaskLog), strTableName); } try { string strSql = Function.SqlStr(dtmLodId.Ticks.ToString()) + "," + this.Config.TaskConfigId.ToString() + "," + Function.BoolToByte(this.IsAuto) + "," + this.PlanTime.Ticks.ToString() + ",0,0," + Function.SqlStr(this.TaskName); strSql = "INSERT INTO " + strTableName + " (" + Tables.TaskLog.TaskLogId + "," + Tables.TaskLog.TaskConfigId + "," + Tables.TaskLog.IsAuto + "," + Tables.TaskLog.PlanTime + "," + Tables.TaskLog.RetryTimes + "," + Tables.TaskLog.LastProgress + "," + Tables.TaskLog.TaskName + ") VALUES (" + strSql + ")"; dbConnection.ExecuteNonQuery(strSql); this.LogId = dtmLodId.Ticks; } catch { if (tryCount > 3) { throw new Exception("保存任务运行日志 " + this.GetType().FullName + " 时发生错误,已重试3次。"); } else { this.Save(tryCount + 1); } } finally { dbConnection.Close(); } }