protected virtual void AppendException(BasicDeliverEventArgs message, Exception exception, int attempt, int depth) { if (!this.CanAppendException(message, exception, attempt, depth)) { return; } message.SetHeader(ExceptionHeaderFormat.FormatWith(attempt, depth, "type"), exception.GetType().ToString()); message.SetHeader(ExceptionHeaderFormat.FormatWith(attempt, depth, "message"), exception.Message); message.SetHeader(ExceptionHeaderFormat.FormatWith(attempt, depth, "stacktrace"), exception.StackTrace ?? string.Empty); this.AppendException(message, exception.InnerException, attempt, depth + 1); }
protected virtual bool CanAppendException(BasicDeliverEventArgs message, Exception exception, int attempt, int depth) { if (exception == null) { return(false); } if (attempt == 0 || depth > 1) { return(true); } var previousType = message.GetHeader(ExceptionHeaderFormat.FormatWith(attempt - 1, 0, "type")).AsString(); var previousMessage = message.GetHeader(ExceptionHeaderFormat.FormatWith(attempt - 1, 0, "message")).AsString(); var previousStackTrace = message.GetHeader(ExceptionHeaderFormat.FormatWith(attempt - 1, 0, "stacktrace")).AsString(); return(exception.GetType().ToString() != previousType || exception.Message != previousMessage || (exception.StackTrace ?? string.Empty) != previousStackTrace); }
protected virtual void AppendException(BasicDeliverEventArgs message, Exception exception, int attempt, int depth) { if (!this.CanAppendException(message, exception, attempt, depth)) { return; } message.SetHeader(ExceptionHeaderFormat.FormatWith(attempt, depth, "type"), exception.GetType().ToString()); message.SetHeader(ExceptionHeaderFormat.FormatWith(attempt, depth, "message"), exception.Message); message.SetHeader(ExceptionHeaderFormat.FormatWith(attempt, depth, "stacktrace"), exception.StackTrace ?? string.Empty); this.AppendException(message, exception.InnerException, attempt, depth + 1); if (depth > 0) { return; } var process = Process.GetCurrentProcess(); message.SetHeader(ExceptionHeaderFormat.FormatWith(attempt, depth, "process-name"), process.ProcessName); message.SetHeader(ExceptionHeaderFormat.FormatWith(attempt, depth, "process-id"), process.Id.ToString(CultureInfo.InvariantCulture)); message.SetHeader(ExceptionHeaderFormat.FormatWith(attempt, depth, "origin-host"), Environment.MachineName.ToLowerInvariant()); message.SetHeader(ExceptionHeaderFormat.FormatWith(attempt, depth, "timestamp"), SystemTime.UtcNow.ToIsoString()); }