Skip to content

Commit e42fe53

Browse files
committed
Port #1494 to main
Fixes #1493 by porting 55010ab to `main`
1 parent 1d5b36a commit e42fe53

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

projects/RabbitMQ.Client/client/api/ShutdownEventArgs.cs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,14 +121,32 @@ public Exception Exception
121121
/// Override ToString to be useful for debugging.
122122
/// </summary>
123123
public override string ToString()
124+
{
125+
return GetMessageCore()
126+
+ (_exception != null ? $", exception={_exception}" : string.Empty);
127+
}
128+
129+
/// <summary>
130+
/// Gets a message suitable for logging.
131+
/// </summary>
132+
/// <remarks>
133+
/// This leaves out the full exception ToString since logging will include it separately.
134+
/// </remarks>
135+
internal string GetLogMessage()
136+
{
137+
return GetMessageCore()
138+
+ (_exception != null ? $", exception={_exception.Message}" : string.Empty);
139+
}
140+
141+
private string GetMessageCore()
124142
{
125143
return $"AMQP close-reason, initiated by {Initiator}"
126144
+ $", code={ReplyCode}"
127145
+ (ReplyText != null ? $", text='{ReplyText}'" : string.Empty)
128146
+ $", classId={ClassId}"
129147
+ $", methodId={MethodId}"
130-
+ (Cause != null ? $", cause={Cause}" : string.Empty)
131-
+ (_exception != null ? $", exception={_exception}" : string.Empty);
148+
+ (Cause != null ? $", cause={Cause}" : string.Empty);
132149
}
150+
133151
}
134152
}

projects/RabbitMQ.Client/client/impl/Connection.Receive.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,16 +175,17 @@ private void TerminateMainloop()
175175

176176
private void HandleMainLoopException(ShutdownEventArgs reason)
177177
{
178+
string message = reason.GetLogMessage();
178179
if (!SetCloseReason(reason))
179180
{
180-
LogCloseError($"Unexpected Main Loop Exception while closing: {reason}", reason.Exception);
181+
LogCloseError($"Unexpected Main Loop Exception while closing: {message}", reason.Exception);
181182
return;
182183
}
183184

184185
_channel0.MaybeSetConnectionStartException(reason.Exception);
185186

186187
OnShutdown(reason);
187-
LogCloseError($"Unexpected connection closure: {reason}", reason.Exception);
188+
LogCloseError($"Unexpected connection closure: {message}", reason.Exception);
188189
}
189190

190191
private async Task HardProtocolExceptionHandlerAsync(HardProtocolException hpe, CancellationToken cancellationToken)

0 commit comments

Comments
 (0)