diff --git a/projects/RabbitMQ.Client/client/api/ShutdownEventArgs.cs b/projects/RabbitMQ.Client/client/api/ShutdownEventArgs.cs
index 2aa672227d..5d756eef95 100644
--- a/projects/RabbitMQ.Client/client/api/ShutdownEventArgs.cs
+++ b/projects/RabbitMQ.Client/client/api/ShutdownEventArgs.cs
@@ -123,17 +123,34 @@ public Exception Exception
///
public string ReplyText { get; private set; }
- ///
- /// Override ToString to be useful for debugging.
- ///
- public override string ToString()
+ private string GetMessageCore()
{
return $"AMQP close-reason, initiated by {Initiator}"
+ $", code={ReplyCode}"
+ (ReplyText != null ? $", text='{ReplyText}'" : string.Empty)
+ $", classId={ClassId}"
+ $", methodId={MethodId}"
- + (Cause != null ? $", cause={Cause}" : string.Empty)
+ + (Cause != null ? $", cause={Cause}" : string.Empty);
+ }
+
+ ///
+ /// Gets a message suitable for logging.
+ ///
+ ///
+ /// This leaves out the full exception ToString since logging will include it separately.
+ ///
+ internal string GetLogMessage()
+ {
+ return GetMessageCore()
+ + (_exception != null ? $", exception={_exception.Message}" : string.Empty);
+ }
+
+ ///
+ /// Override ToString to be useful for debugging.
+ ///
+ public override string ToString()
+ {
+ return GetMessageCore()
+ (_exception != null ? $", exception={_exception}" : string.Empty);
}
}
diff --git a/projects/RabbitMQ.Client/client/impl/Connection.cs b/projects/RabbitMQ.Client/client/impl/Connection.cs
index 477baa7910..20950dec42 100644
--- a/projects/RabbitMQ.Client/client/impl/Connection.cs
+++ b/projects/RabbitMQ.Client/client/impl/Connection.cs
@@ -455,16 +455,17 @@ public void HandleDomainUnload(object sender, EventArgs ea)
public void HandleMainLoopException(ShutdownEventArgs reason)
{
+ string message = reason.GetLogMessage();
if (!SetCloseReason(reason))
{
- LogCloseError($"Unexpected Main Loop Exception while closing: {reason}", reason.Exception);
+ LogCloseError($"Unexpected Main Loop Exception while closing: {message}", reason.Exception);
return;
}
_model0.MaybeSetConnectionStartException(reason.Exception);
OnShutdown();
- LogCloseError($"Unexpected connection closure: {reason}", reason.Exception);
+ LogCloseError($"Unexpected connection closure: {message}", reason.Exception);
}
public bool HardProtocolExceptionHandler(HardProtocolException hpe)