Skip to content

Commit 55010ab

Browse files
eerhardtlukebakken
authored andcommitted
Remove StackTrace from EventSource Message
When logging connection exception information to the EventSoruce we are putting the full exception ToString in the Message which clutters it to the users. Instead, just put the Exception.Message in the EventSource event message. The full exception information comes in the details of the EventSource event. Fix #1493
1 parent dd10278 commit 55010ab

File tree

2 files changed

+25
-7
lines changed

2 files changed

+25
-7
lines changed

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

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,17 +123,34 @@ public Exception Exception
123123
/// </summary>
124124
public string ReplyText { get; private set; }
125125

126-
/// <summary>
127-
/// Override ToString to be useful for debugging.
128-
/// </summary>
129-
public override string ToString()
126+
private string GetMessageCore()
130127
{
131128
return $"AMQP close-reason, initiated by {Initiator}"
132129
+ $", code={ReplyCode}"
133130
+ (ReplyText != null ? $", text='{ReplyText}'" : string.Empty)
134131
+ $", classId={ClassId}"
135132
+ $", methodId={MethodId}"
136-
+ (Cause != null ? $", cause={Cause}" : string.Empty)
133+
+ (Cause != null ? $", cause={Cause}" : string.Empty);
134+
}
135+
136+
/// <summary>
137+
/// Gets a message suitable for logging.
138+
/// </summary>
139+
/// <remarks>
140+
/// This leaves out the full exception ToString since logging will include it separately.
141+
/// </remarks>
142+
internal string GetLogMessage()
143+
{
144+
return GetMessageCore()
145+
+ (_exception != null ? $", exception={_exception.Message}" : string.Empty);
146+
}
147+
148+
/// <summary>
149+
/// Override ToString to be useful for debugging.
150+
/// </summary>
151+
public override string ToString()
152+
{
153+
return GetMessageCore()
137154
+ (_exception != null ? $", exception={_exception}" : string.Empty);
138155
}
139156
}

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -455,16 +455,17 @@ public void HandleDomainUnload(object sender, EventArgs ea)
455455

456456
public void HandleMainLoopException(ShutdownEventArgs reason)
457457
{
458+
string message = reason.GetLogMessage();
458459
if (!SetCloseReason(reason))
459460
{
460-
LogCloseError($"Unexpected Main Loop Exception while closing: {reason}", reason.Exception);
461+
LogCloseError($"Unexpected Main Loop Exception while closing: {message}", reason.Exception);
461462
return;
462463
}
463464

464465
_model0.MaybeSetConnectionStartException(reason.Exception);
465466

466467
OnShutdown();
467-
LogCloseError($"Unexpected connection closure: {reason}", reason.Exception);
468+
LogCloseError($"Unexpected connection closure: {message}", reason.Exception);
468469
}
469470

470471
public bool HardProtocolExceptionHandler(HardProtocolException hpe)

0 commit comments

Comments
 (0)