Skip to content

Commit b06aff6

Browse files
authored
ILogger.Debug() calls that use string interpolation or invoking methods to get log arguments wrapped in IsDebugEnabled (#1205)
1 parent 36ed36c commit b06aff6

File tree

6 files changed

+49
-15
lines changed

6 files changed

+49
-15
lines changed

src/Transport/Administration/QueueCreator.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@ public async Task Create(ServiceBusAdministrationClient adminClient, string[] qu
3131
}
3232
catch (ServiceBusException sbe) when (sbe.Reason == ServiceBusFailureReason.MessagingEntityAlreadyExists)
3333
{
34-
Logger.Debug($"Queue {queue.Name} already exists");
34+
if (Logger.IsDebugEnabled)
35+
{
36+
Logger.Debug($"Queue {queue.Name} already exists");
37+
}
3538
}
3639
catch (ServiceBusException sbe) when (sbe.IsTransient)// An operation is in progress.
3740
{

src/Transport/EventRouting/MigrationTopologyCreator.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,10 @@ await adminClient.CreateSubscriptionAsync(subscription,
7979
catch (ServiceBusException sbe) when
8080
(sbe.Reason == ServiceBusFailureReason.MessagingEntityAlreadyExists)
8181
{
82-
Logger.Debug($"Default subscription rule for topic {subscription.TopicName} already exists");
82+
if (Logger.IsDebugEnabled)
83+
{
84+
Logger.Debug($"Default subscription rule for topic {subscription.TopicName} already exists");
85+
}
8386
}
8487
catch (ServiceBusException sbe) when (sbe.IsTransient) // An operation is in progress.
8588
{

src/Transport/EventRouting/MigrationTopologySubscriptionManager.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,10 @@ await CreationOptions.AdministrationClient.CreateSubscriptionAsync(subscription,
120120
}
121121
catch (ServiceBusException sbe) when (sbe.Reason == ServiceBusFailureReason.MessagingEntityAlreadyExists)
122122
{
123-
Logger.Debug($"Default subscription rule for topic {subscription.TopicName} already exists");
123+
if (Logger.IsDebugEnabled)
124+
{
125+
Logger.Debug($"Default subscription rule for topic {subscription.TopicName} already exists");
126+
}
124127
}
125128
catch (ServiceBusException sbe) when (sbe.IsTransient)// An operation is in progress.
126129
{

src/Transport/Receiving/MessagePump.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,10 @@ async Task OnProcessMessage(ProcessMessageEventArgs arg)
152152
}
153153
catch (Exception ex) when (ex.IsCausedBy(messageProcessingCancellationTokenSource!.Token))
154154
{
155-
Logger.Debug("Message processing canceled.", ex);
155+
if (Logger.IsDebugEnabled)
156+
{
157+
Logger.Debug("Message processing canceled.", ex);
158+
}
156159
}
157160
}
158161

@@ -216,7 +219,10 @@ await processor.CloseAsync(cancellationToken)
216219
}
217220
catch (Exception ex) when (ex.IsCausedBy(cancellationToken))
218221
{
219-
Logger.Debug($"Operation canceled while stopping the receiver {processor.EntityPath}.", ex);
222+
if (Logger.IsDebugEnabled)
223+
{
224+
Logger.Debug($"Operation canceled while stopping the receiver {processor.EntityPath}.", ex);
225+
}
220226
}
221227
}
222228

src/Transport/Receiving/ProcessMessageEventArgsExtensions.cs

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ public static async ValueTask<bool> TrySafeCompleteMessage(this ProcessMessageEv
1616
{
1717
if (transportTransactionMode == TransportTransactionMode.ReceiveOnly && messagesToBeCompleted.TryGet(message.GetMessageId(), out _))
1818
{
19-
Logger.DebugFormat("Received message with id '{0}' was marked as successfully completed. Trying to immediately acknowledge the message without invoking the pipeline.", message.GetMessageId());
19+
if (Logger.IsDebugEnabled)
20+
{
21+
Logger.DebugFormat("Received message with id '{0}' was marked as successfully completed. Trying to immediately acknowledge the message without invoking the pipeline.", message.GetMessageId());
22+
}
2023

2124
try
2225
{
@@ -56,8 +59,11 @@ await args.SafeAbandonMessage(message, transportTransactionMode, cancellationTok
5659
}
5760
catch (Exception e) when (!e.IsCausedBy(cancellationToken))
5861
{
59-
// nothing we can do about it, message will be retried
60-
Logger.Debug($"Error abandoning the message with id '{message.GetMessageId()}' because the lock has expired at '{message.LockedUntil}.", e);
62+
if (Logger.IsDebugEnabled)
63+
{
64+
// nothing we can do about it, message will be retried
65+
Logger.Debug($"Error abandoning the message with id '{message.GetMessageId()}' because the lock has expired at '{message.LockedUntil}.", e);
66+
}
6167
}
6268
}
6369
return false;
@@ -80,8 +86,11 @@ await args.DeadLetterMessageAsync(message,
8086
}
8187
catch (Exception deadLetterEx) when (!deadLetterEx.IsCausedBy(cancellationToken))
8288
{
83-
// nothing we can do about it, message will be retried
84-
Logger.Debug("Error dead lettering poisoned message.", deadLetterEx);
89+
if (Logger.IsDebugEnabled)
90+
{
91+
// nothing we can do about it, message will be retried
92+
Logger.Debug("Error dead lettering poisoned message.", deadLetterEx);
93+
}
8594
}
8695
}
8796
else
@@ -126,9 +135,12 @@ public static async Task SafeAbandonMessage(this ProcessMessageEventArgs args, S
126135
}
127136
catch (ServiceBusException e) when (e.Reason == ServiceBusFailureReason.MessageLockLost)
128137
{
129-
// We tried to abandon the message because it needs to be retried, but the lock was lost.
130-
// the message will reappear on the next receive anyway so we can just ignore this case.
131-
Logger.DebugFormat("Attempted to abandon the message with id '{0}' but the lock was lost.", message.GetMessageId());
138+
if (Logger.IsDebugEnabled)
139+
{
140+
// We tried to abandon the message because it needs to be retried, but the lock was lost.
141+
// the message will reappear on the next receive anyway so we can just ignore this case.
142+
Logger.DebugFormat("Attempted to abandon the message with id '{0}' but the lock was lost.", message.GetMessageId());
143+
}
132144
}
133145
}
134146
}

src/Transport/Sending/MessageDispatcher.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,11 @@ async Task DispatchBatchOrFallbackToIndividualSendsForDestination(string destina
221221
// when it tries to establish a link to a non-existing entity.
222222
catch (ServiceBusException e) when (isMulticast && e.Reason == ServiceBusFailureReason.MessagingEntityNotFound)
223223
{
224-
Log.Debug($"Skipping sending messages to topic {destination} because the destination does not exist.");
224+
if (Log.IsDebugEnabled)
225+
{
226+
Log.Debug($"Skipping sending messages to topic {destination} because the destination does not exist.");
227+
}
228+
225229
return;
226230
}
227231
}
@@ -299,7 +303,10 @@ async Task DispatchForDestination(string destination, bool isMulticast, ServiceB
299303
}
300304
catch (ServiceBusException e) when (isMulticast && e.Reason == ServiceBusFailureReason.MessagingEntityNotFound)
301305
{
302-
Log.Debug($"Sending message with message ID '{message.MessageId}' to topic {destination} failed because the destination does not exist.");
306+
if (Log.IsDebugEnabled)
307+
{
308+
Log.Debug($"Sending message with message ID '{message.MessageId}' to topic {destination} failed because the destination does not exist.");
309+
}
303310
}
304311
}
305312
}

0 commit comments

Comments
 (0)