Exemplo n.º 1
0
        /// <summary>
        /// Log any executed command by user
        /// </summary>
        /// <param name="module"></param>
        /// <param name="status"></param>
        /// <param name="command"></param>
        /// <param name="account"></param>
        /// <param name="newValue"></param>
        /// <param name="oldValue"></param>
        public static void CommandLog(bool status, ClinicEnums.Module module, string command, AccountModel account, object newValue = null, object oldValue = null)
        {
            try
            {
                var log = new LogModel
                {
                    Start        = DateTime.Now,
                    Module       = module.ToString(),
                    Status       = status ? "SUCCESS" : "ERROR",
                    Command      = command,
                    UserName     = account.UserName,
                    Organization = account.Organization,
                    OldValue     = oldValue is null ? null : JsonConvert.SerializeObject(oldValue),
                    NewValue     = newValue is null ? null : JsonConvert.SerializeObject(newValue),
                    CreatedBy    = account.UserCode,
                    CreatedDate  = DateTime.Now
                };

                var _entity = Mapper.Map <LogModel, Log>(log);

                using (var context = new klinikEntities())
                {
                    context.Logs.Add(_entity);
                    context.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                using (EventLog eventLog = new EventLog("Application"))
                {
                    eventLog.Source = "Application";
                    eventLog.WriteEntry(ex.GetAllMessages(), EventLogEntryType.Error, 101, 1);
                }
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// Log an error
 /// </summary>
 /// <param name="module"></param>
 /// <param name="status"></param>
 /// <param name="command"></param>
 /// <param name="account"></param>
 /// <param name="ex"></param>
 public static void ErrorLog(ClinicEnums.Module module, string command, AccountModel account, Exception ex)
 {
     CommandLog(false, module, command, account, ex.GetAllMessages());
 }