public static void WriteToDb(Record record) { try { var logsRs = new IMRecordset(MD.SysLogs.TableName, IMRecordset.Mode.ReadWrite); using (var logsRsScope = logsRs.OpenForAdd( MD.SysLogs.Fields.Id, MD.SysLogs.Fields.Event, MD.SysLogs.Fields.TableName, MD.SysLogs.Fields.Count, MD.SysLogs.Fields.Info, MD.SysLogs.Fields.Who, MD.SysLogs.Fields.When )) { var currentTime = DateTime.Now; var currentUser = IM.ConnectedUser(); logsRs.AddNew(MD.SysLogs.TableName, MD.SysLogs.Fields.Id); logsRs.Put(MD.SysLogs.Fields.Event, record.Type.ToString()); logsRs.Put(MD.SysLogs.Fields.TableName, MD.SysLogs.TableName); logsRs.Put(MD.SysLogs.Fields.Count, 1); logsRs.Put(MD.SysLogs.Fields.Info, $"{record.Process}: {record.Message}"); logsRs.Put(MD.SysLogs.Fields.Who, currentUser); logsRs.Put(MD.SysLogs.Fields.When, currentTime); logsRs.Update(); if (record.Duration > 0) { logsRs.AddNew(MD.SysLogs.TableName, MD.SysLogs.Fields.Id); logsRs.Put(MD.SysLogs.Fields.Event, record.Type.ToString()); logsRs.Put(MD.SysLogs.Fields.TableName, MD.SysLogs.TableName); logsRs.Put(MD.SysLogs.Fields.Count, 1); logsRs.Put(MD.SysLogs.Fields.Info, $"{record.Process}: Duration {record.Duration}ms"); logsRs.Put(MD.SysLogs.Fields.Who, currentUser); logsRs.Put(MD.SysLogs.Fields.When, currentTime); logsRs.Update(); } if (!string.IsNullOrEmpty(record.Data)) { logsRs.AddNew(MD.SysLogs.TableName, MD.SysLogs.Fields.Id); logsRs.Put(MD.SysLogs.Fields.Event, record.Type.ToString()); logsRs.Put(MD.SysLogs.Fields.TableName, MD.SysLogs.TableName); logsRs.Put(MD.SysLogs.Fields.Count, 1); logsRs.Put(MD.SysLogs.Fields.Info, $"{record.Process}: {record.Data}"); logsRs.Put(MD.SysLogs.Fields.Who, currentUser); logsRs.Put(MD.SysLogs.Fields.When, currentTime); logsRs.Update(); } } } catch (Exception e) { System.Windows.Forms.MessageBox.Show(e.ToString(), "Logger.WriteToDb", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error); } }