コード例 #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;

            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);
                    }
                }
            }
        }