private IReadOnlyList <Exception> Flatten(Exception exception)
        {
            exception.AssertNotNull("exception");

            var output = new List <Exception>();

            this.Flatten(exception, output);
            return(output);
        }
Beispiel #2
0
        public void LogRequestException(HttpRequestMessage request, Exception exception)
        {
            request.AssertNotNull(nameof(request));
            exception.AssertNotNull(nameof(exception));

            if (LogRequestExceptions)
            {
                var message = new StringBuilder();
                message.AppendLine($"HTTP request error - '{exception.Message}'");
                message.AppendLine(FormatRequest(request));

                _logger.LogError(message.ToString(), exception);
            }
        }
Beispiel #3
0
            private void Log(LogLevel level, Exception exception, string format, params object[] args)
            {
                exception.AssertNotNull(nameof(exception));
                format.AssertNotNull(nameof(format));
                args.AssertNotNull(nameof(format));

                if (!_owner.IsLevelEnabled(level))
                {
                    return;
                }

                var message = string.Format(CultureInfo.InvariantCulture, format, args) + " : " + exception.ToString();

                Log(level, message);
            }
        private static void VerifyAssumptionThrows <TRoot, TException>(TRoot root
                                                                       , Exception innerException, Action <TRoot, Exception> action, string expectedMessage = DefaultMessage)
            where TException : Exception
        {
            // ReSharper disable once ImplicitlyCapturedClosure
            Action wrapper = () => action.AssertNotNull().Invoke(root, innerException);

            // ReSharper disable once ImplicitlyCapturedClosure
            wrapper.AssertNotNull().AssertThrowsAny <TException>()
            .Verify(ex =>
            {
                ex.AssertNotNull().Message.AssertNotNull().AssertEqual(expectedMessage);
                ex.InnerException.AssertNotNull().AssertSame(innerException.AssertNotNull());
            });
        }
        protected virtual void LogException(Exception e, HttpContext context)
        {
            e.AssertNotNull("e");
            // Fire an event to check if listeners want to filter out
            // logging of the uncaught exception.
            var args = new ExceptionFilterEventArgs(e, context);

            OnFiltering(args);

            if (args.Dismissed)
            {
                return;
            }

            //Run the module
            ErrorLogEntry entry = null;

            try
            {
                var error = new Error(e, context);
                new ErrorHandlerDelegate(err => new CustomErrorHandler()
                {
                    Configuration = SettingsManager.Config
                }.HandleError(err))(error);
            }
            catch (Exception localException)
            {
                //
                // IMPORTANT! We swallow any exception raised during the
                // logging and send them out to the trace . The idea
                // here is that logging of exceptions by itself should not
                // be  critical to the overall operation of the application.
                // The bad thing is that we catch ANY kind of exception,
                // even system ones and potentially let them slip by.
                Trace.WriteLine(localException);
            }

            if (entry != null)
            {
                OnLogged(new ErrorLoggedEventArgs(entry));
            }
        }