Exemplo n.º 1
0
        public void InsertActionLogDeleteItem(string tableModified, string Message, object[] valueOldObj, object valueNewObj, string LogLevel)
        {
            AdActionLog _actionLog = new AdActionLog(_accessor);

            if (valueOldObj != null)
            {
                var valueOld = JsonConvert.SerializeObject(valueOldObj);
                _actionLog.DataOld = valueOld;
            }
            //  if (valueOldObj.Any())
            //{
            //    var valueOld = JsonConvert.SerializeObject(valueOldObj);
            //    _actionLog.DataOld = valueOld;

            //}
            if (valueNewObj != null)
            {
                var valueNew = JsonConvert.SerializeObject(valueNewObj);
                _actionLog.DataNew = valueNew;
            }

            _actionLog.TableModified        = tableModified;
            _actionLog.ActionLogApplication = "Admin";
            _actionLog.Message  = Message;
            _actionLog.LogLevel = LogLevel;

            //_context.Add(_actionLog);
            //_context.SaveChanges();
        }
Exemplo n.º 2
0
        public void Log <TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func <TState, Exception, string> formatter)
        {
            if (!IsEnabled(logLevel))
            {
                return;
            }
            if (formatter == null)
            {
                throw new ArgumentNullException(nameof(formatter));
            }
            var message = formatter(state, exception);

            if (string.IsNullOrEmpty(message))
            {
                return;
            }

            if (exception != null)
            {
                message += "\n" + exception.ToString();
            }
            message = message.Length > MessageMaxLength?message.Substring(0, MessageMaxLength) : message;

            if (eventId.Id == LoggingEvents.LogDb)
            {
                // Insert log to database
                AdActionLog actionLog = new AdActionLog(_accessor);
                actionLog.LogLevel = logLevel.ToString();
                actionLog.Message  = message;
                //actionLog.Data = "";

                _context = _accessor.HttpContext.RequestServices.GetService <EIMDBContext>();
                _context.AdActionLogs.Add(actionLog);
                _context.SaveChanges();
            }
        }