Beispiel #1
0
        private void ErrorNotifierOnErrorOccured(object sender, NoodleEventArgs <Exception> errorEventArgs)
        {
            if (errorEventArgs.Item == null)
            {
                return;
            }
            if (!LogStore.IsErrorLoggable(errorEventArgs.Item))
            {
                return;
            }

            try
            {
                if (errorEventArgs.Item is LogException)
                {
                    _logger.InsertLog((errorEventArgs.Item as LogException).LogLevel,
                                      (errorEventArgs.Item as LogException).ShortMessage,
                                      (errorEventArgs.Item as LogException).FullMessage,
                                      errorEventArgs.Item);
                }
                else
                {
                    _logger.Error("IErrorNotifier", errorEventArgs.Item);
                }
            }catch (Exception ex)
            {
                new Logger <ErrorNotifierLogger>().Error("There was a problem logging an exception from IErrorNotifier. " + ex.Message);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Inserts a log item
        /// </summary>
        /// <param name="logLevel">Log level</param>
        /// <param name="shortMessage">The short message</param>
        /// <param name="fullMessage">The full message</param>
        /// <param name="exception">The error associated with this log</param>
        /// <param name="user">The user to associate log record with</param>
        /// <param name="requestContext">The request context. If this is supplied, additional info will be logged, like ip, post/server variables, etc</param>
        /// <returns>A log item</returns>
        public Log InsertLog(LogLevel logLevel, string shortMessage, string fullMessage = "", Exception exception = null, string user = null)
        {
            Exception ex = null;

            if (exception != null)
            {
                if (IsBuiltInException(exception))
                {
                    ex = exception.GetBaseException();
                }
            }

            var log = new Log()
            {
                LogLevel     = logLevel,
                ShortMessage = shortMessage ?? string.Empty,
                FullMessage  = fullMessage ?? string.Empty,
                User         = user,
                CreatedOnUtc = CommonHelper.CurrentTime()
            };

            if (ex != null)
            {
                if (string.IsNullOrEmpty(shortMessage))
                {
                    log.ShortMessage = ex.Message;
                }
                else
                {
                    log.ShortMessage += Environment.NewLine + ex.Message;
                }

                log.FullMessage += Environment.NewLine + "Full Trace:" + Environment.NewLine + ex.StackTrace;
            }

            foreach (var customData in LogStore.GetCustomData(ex ?? new LogException(logLevel, shortMessage, fullMessage), _container))
            {
                log.CustomData.Add(customData.Key, customData.Value);
            }

            _logCollection.Insert(log);

            return(log);
        }