Esempio n. 1
0
        public virtual void Log(Exception ex, bool isFatal = false)
        {
            if (ex == null)
            {
                return;
            }
            if (ex is System.Threading.ThreadAbortException)
            {
                return;
            }
            var context = HttpContext.Current;

            LoggerConfigurationManager.LoadConfigFileAndSetLoggerConfigProp(context?.Server);
            bool doNotSendEmail;
            var  exMsg = BuildErrorMsg(ex, context, out doNotSendEmail);

            if (!string.IsNullOrWhiteSpace(exMsg))
            {
                _logger.Log(isFatal ? LogLevel.Fatal : LogLevel.Error, exMsg);
                if (false == doNotSendEmail)
                {
                    try
                    {
                        Emailer.EmailLogMessage(exMsg, false);
                    }
                    catch (Exception ex2)
                    {
                        Log(LoggingLevel.Warn, "Error sending log email: " + ex2.GetFullExceptionMessage());
                    }
                }
            }
        }
Esempio n. 2
0
        public virtual void Log(Exception ex, bool isFatal = false)
        {
            if (ex == null)
            {
                return;
            }
            if (ex is System.Threading.ThreadAbortException)
            {
                return;
            }
            var context = HttpContext.Current;

            bool doNotSendEmail;
            var  exMsg = BuildErrorMsg(ex, context, out doNotSendEmail);

            if (!string.IsNullOrWhiteSpace(exMsg))
            {
                LoggerConfigurationManager.LoadConfigFileAndSetLoggerConfigProp(context?.Server);
                var level = isFatal ? LoggingLevel.Fatal : LoggingLevel.Error;

                _logger.Log(GetLogLevel(level), exMsg);

                if (_logToDb)
                {
                    new LogLogic().InsertLog(_logger.Name, context, level, ex.Message, exMsg);
                }

                if (false == doNotSendEmail)
                {
                    try
                    {
                        Emailer.EmailLogMessage(exMsg, false);
                    }
                    catch (Exception ex2)
                    {
                        Log(LoggingLevel.Warn, "Error sending log email: {0}", ex2.Message);
                    }
                }
            }
        }