/// <summary>
        ///
        /// </summary>
        public ExceptionWrapper(Exception error)
        {
            #region Validate parameters
            if (error == null)
            {
                throw new ArgumentNullException("error");
            }
            #endregion

            this.ErrorType = error.GetType().Name;
            this.Time      = DateTime.Now;
            this.Message   = error.Message;
            string allMessages = error.AllMessages();
            if (!String.IsNullOrEmpty(allMessages))
            {
                this.InnerMessages = allMessages.Replace(this.Message, "").Trim('\r', '\n');
            }

            this.FullMessage = error.ToString();
            this.Source      = error.Source;
            this.StackTrace  = error.StackTrace;
            if (error.InnerException != null)
            {
                this.InnerException = new ExceptionWrapper(error.InnerException);
            }
        }
Esempio n. 2
0
        public ErrorResult(Exception ex, HttpActionContext actionContext) : base(new HttpResponseMessage(HttpStatusCode.InternalServerError))
        {
            string message = ex.AllMessages().Replace(Environment.NewLine, " ");

            this.Response.ReasonPhrase = message;
            this.Response.Content      = new ObjectContent(typeof(Error), new Error("error", message, message), actionContext.ControllerContext.Configuration.Formatters.JsonFormatter);
        }
Esempio n. 3
0
            public void WhenNoInnerException_ThenReturnString()
            {
                var sut = new Exception(Message1);

                var result = sut.AllMessages();

                Assert.That(result, Is.EqualTo(Message1));
            }
Esempio n. 4
0
        public static void Error(string text, Exception ex)
        {
            text = History(SeverityLevel.Error, text);
            StringBuilder builder = new StringBuilder(text);

            builder.AppendLine(ex.AllMessages())
            .AppendLine(ex.StackTrace);
            Append(Path, builder.ToString());
        }
Esempio n. 5
0
        public override void OnException(HttpActionExecutedContext context)
        {
            Exception           ex       = context.Exception;
            string              message  = Regex.Replace(ex.AllMessages(), @"\r\n?|\n", "-");
            HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.InternalServerError);

            response.ReasonPhrase = message;
            response.Content      = new ObjectContent(typeof(Error), new Error("error", message, ex), new JsonMediaTypeFormatter());
            context.Response      = response;
        }
Esempio n. 6
0
        public static void AccessException(this IIdempotenceService service, ILog log, Exception ex, IPipeline pipeline)
        {
            Guard.AgainstNull(service, nameof(service));
            Guard.AgainstNull(log, nameof(log));
            Guard.AgainstNull(ex, nameof(ex));
            Guard.AgainstNull(pipeline, nameof(pipeline));

            log.Fatal(string.Format(Resources.FatalIdempotenceServiceException, service.GetType().FullName,
                ex.AllMessages()));

            pipeline.Abort();
        }
        public static void AccessException(this IIdempotenceService service, ILog log, Exception ex, Pipeline pipeline)
        {
            Guard.AgainstNull(service, "service");
            Guard.AgainstNull(log, "log");
            Guard.AgainstNull(ex, "ex");
            Guard.AgainstNull(pipeline, "pipeline");

            log.Fatal(string.Format(EsbResources.FatalIdempotenceServiceException, service.GetType().FullName,
                                    ex.AllMessages()));

            pipeline.Abort();
        }
Esempio n. 8
0
        private string GetMessageWithoutNewLines(Exception ex)
        {
            if (ex == null)
            {
                return(string.Empty);
            }

            string msg = ex
                         .AllMessages()
                         .Replace(Environment.NewLine, " ") // \r\n
                         .Replace("\n", " ");

            return(msg);
        }
Esempio n. 9
0
            public void WhenMultipleInnerExceptions_ThenReturnString()
            {
                string expected =
                    Message1 + Environment.NewLine +
                    "-- " + Message2 + Environment.NewLine +
                    "---- " + Message3;

                var ex3 = new Exception(Message3);
                var ex2 = new Exception(Message2, ex3);

                var sut = new Exception(Message1, ex2);

                var result = sut.AllMessages();

                Assert.That(result, Is.EqualTo(expected));
            }
        public static HandlerExceptionEvent CoreHandlerExceptionEvent(Exception ex, string hostName,
                                                                      string[] ipAddresses)
        {
            Guard.AgainstNull(ex, "ex");

            return(new HandlerExceptionEvent
            {
                Source = ex.Source,
                Message = ex.AllMessages(),
                StackTrace = ex.ToString(),
                ExceptionTypeFullName = ex.GetType().FullName,
                TargetSite = ex.TargetSite.ToString(),
                TargetSiteName = ex.TargetSite.Name,
                TargetSiteMemberType = ex.TargetSite.MemberType.ToString(),
                TargetSiteDeclaringTypeFullName = ex.TargetSite.DeclaringType.ToString(),
                TargetSiteModuleFullyQualifiedName = ex.TargetSite.Module.FullyQualifiedName,
                TargetSiteModuleAssemblyFullName = ex.TargetSite.Module.Assembly.FullName,
                DateThrown = DateTime.Now,
                MachineName = Environment.MachineName,
                HostName = hostName,
                IPAddresses = ipAddresses
            });
        }
        public static string ToDebugString(this Exception ex)
        {
            StringBuilder sbMessage = new StringBuilder(ex.GetDetailedExceptionMessage(false));

            //String s = "\"" + sbMessage + "\"";
            //Debug.WriteLine(s);

            sbMessage.Combine(ex.AllMessages(), Utils.NewLine);

            // Usage of GetDetailedExceptionMessage gives us type name anyway, so no need to duplicate it
            //StringBuilder sbFull = new StringBuilder(ex.TrimExceptionClassName());
            //if (sbMessage.Length > 0)
            //{
            //    sbFull.Append(": ");
            //    sbFull.Append(sbMessage);
            //}

            StringBuilder sbFull = sbMessage;

            if (ex.InnerException != null)
            {
                sbFull.AppendLine();
                sbFull.Append("Inner exception: ");
                sbFull.Append(ex.InnerException.ToDebugString());
                if (!String.IsNullOrEmpty(ex.InnerException.GetFullStackTrace()))
                {
                    sbFull.Append(Utils.NewLine + "   --- End of inner exception stack trace ---");
                }
            }

            sbFull.Combine(ex.GetFullStackTrace(), Utils.NewLine);

            //ex.SetDirty(false);

            return(sbFull.ToString());
        }
        public void AllMessages_ExceptionNull()
        {
            Exception e = null;

            e.AllMessages();
        }
Esempio n. 13
0
 public ErrorResult(HttpStatusCode statusCode, Error error, Exception ex, HttpActionContext actionContext) : base(new HttpResponseMessage(statusCode))
 {
     error.Message = string.IsNullOrEmpty(error.Message) ? ex.AllMessages().Replace(Environment.NewLine, " ") : error.Message;
     this.Response.ReasonPhrase = ex?.AllMessages().Replace(Environment.NewLine, " ") ?? "";
     this.Response.Content      = new ObjectContent(typeof(Error), error, actionContext.ControllerContext.Configuration.Formatters.JsonFormatter);
 }
Esempio n. 14
0
 public ErrorResult(HttpStatusCode statusCode, string type, string message, object content, Exception ex, HttpActionContext actionContext) : base(new HttpResponseMessage(statusCode))
 {
     message = string.IsNullOrEmpty(message) ? ex.AllMessages().Replace(Environment.NewLine, " ") : message;
     this.Response.ReasonPhrase = ex.AllMessages().Replace(Environment.NewLine, " ");
     this.Response.Content      = new ObjectContent(typeof(Error), new Error(type, message, content), actionContext.ControllerContext.Configuration.Formatters.JsonFormatter);
 }