private static List<AuditLog> GetAuditList(string Q, SqlParameterCollection oParams, SqlUtil sql, TDatabase AuditDB) { if (sql == null) sql = SqlUtil.Get(AuditDB); List<AuditLog> headers = new List<AuditLog>(); if ((long)oParams["@ID"].Value == 0) return headers; DataTable oTable = sql.ExecuteSingleResultSetSQLQuery(Q, oParams); if (oTable.Rows.Count == 0) return headers; //each unique header has a list of the details long CurrId = -1; long id; AuditFields fields = null; foreach (DataRow r in oTable.Rows) { id = DataUtils.LongZeroIfNull(r["ID"]); if (id != CurrId) { AuditLog a = new AuditLog(r, false); headers.Add(a); fields = a.mFieldChanges; CurrId = id; } fields.Add(r); } return headers; }
private void CreateAudit(int type, AuditFields af) { if (AdditionalAuditData != null) { string oldVal; string newVal; foreach (KeyValuePair<string, string[]> AuditEntry in AdditionalAuditData.UpdateList) { AuditFields.ExtractAuditValue(AuditEntry.Value, out oldVal, out newVal); af.Add((string)AuditEntry.Key, oldVal, newVal); } AdditionalAuditData = null; } string EventSrc = null; long EventID = 0; try { AuditLog al = new AuditLog((long)type, TableName + ":Audit", ID, EventSrc, EventID, af, AuditHistoryDatabase); //mLastAuditID is used for concurrency checking if (AuditHistoryDatabase == TDatabase.Unknown) mLastAuditID = al.Save(AuditLog.CompletionStatus.Success, Process.GetCurrentProcess().ProcessName, this.sqlUtil); else mLastAuditID = al.Save(AuditLog.CompletionStatus.Success, Process.GetCurrentProcess().ProcessName); } catch (Exception) { // don't crash the overall delete if the audit record failed to insert // TODO - log this error somewhere else } }
public static void AuditException(TDatabase db, Exception x, string msg, MethodBase ErrorOriginatingMethod) { try { if (bRecursiveCall) return; bRecursiveCall = true; AuditFields changelist = new AuditFields(); AddExceptionInfo(x, ErrorOriginatingMethod, changelist); string EventSrc = Environment.MachineName; long EventID = 0; AuditLog l = new AuditLog(0, "Exception", 0, EventSrc, EventID, changelist, db); l.Recover = true; l.Save(AuditLog.CompletionStatus.Exception, msg, true); } catch { } finally { bRecursiveCall = false; } }