public static void CreateRecordLogEntry <RecordLogType>(this DCDContext dc, int recordId, ImportLog importLog, RecordImportResult result, RecordImportOperation operation, string notes) where RecordLogType : IDCDRecordImportLog, new() { dc.CreateRecordLogEntry <RecordLogType>(recordId, importLog, result, operation, notes, null); }
public static void CreateRecordLogEntry <RecordLogType>(this DCDContext dc, int recordId, ImportLog importLog, RecordImportResult result, RecordImportOperation operation, string notes, Exception e) where RecordLogType : IDCDRecordImportLog, new() { try { RecordLogType log = new RecordLogType(); log.RecordId = recordId; log.ImportLog = dc.ImportLogs.FirstOrDefault(w => w.Id == importLog.Id); log.Result = result.ToString(); log.Operation = operation.ToString(); log.Notes = notes + (e != null ? $"[{e.ToString()}]" : string.Empty); log.TimeStamp = DateTime.Now; log.InsertRecordOnSubmit(dc); dc.SubmitChanges(); } catch (Exception ex) { DCDImportLogger.Error("Error writing log message to database", ex); } if (result == RecordImportResult.Failure) { if (e != null) { DCDImportLogger.Error("Error processing record " + recordId + ". " + notes, e); } else { DCDImportLogger.Error("Error processing record " + recordId + ". " + notes); } } else { DCDImportLogger.Info("Successfully processed record " + recordId + "."); } }