Skip to content

Commit

Permalink
Log message should include the message type (#1300)
Browse files Browse the repository at this point in the history
* "cannot be forwarded to its destination queue" log message should include the message type

* used NServiceBus constant value for the header

* Update src/NServiceBus.Transport.SqlServer/Receiving/ProcessStrategy.cs

* Use ErrorFormat

* Critical error could also log message type if available

* Cosmetics

* Formatting

* Revert "Critical error could also log message type if available"

This reverts commit 2798aba

---------

Co-authored-by: Daniel Marbach <[email protected]>
  • Loading branch information
poornimanayar and danielmarbach authored Feb 29, 2024
1 parent 7054177 commit 14c0f33
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions src/NServiceBus.Transport.SqlServer/Receiving/ProcessStrategy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
using NServiceBus.Logging;
using Unicast.Queuing;


abstract class ProcessStrategy
{
protected TableBasedQueue InputQueue;
Expand Down Expand Up @@ -54,7 +53,7 @@ protected async Task<ErrorHandleResult> HandleError(Exception exception, Message
try
{
var errorContext = new ErrorContext(exception, message.Headers, message.TransportId, message.Body, transportTransaction, processingAttempts, InputQueue.Name, context);
errorContext.Message.Headers.Remove(ForwardHeader);
_ = errorContext.Message.Headers.Remove(ForwardHeader);

return await onError(errorContext, cancellationToken).ConfigureAwait(false);
}
Expand All @@ -72,10 +71,7 @@ protected async Task<ErrorHandleResult> HandleError(Exception exception, Message

protected async Task<bool> TryHandleDelayedMessage(Message message, SqlConnection connection, SqlTransaction transaction, CancellationToken cancellationToken = default)
{
if (message.Headers.TryGetValue(ForwardHeader, out var forwardDestination))
{
message.Headers.Remove(ForwardHeader);
}
_ = message.Headers.Remove(ForwardHeader, out var forwardDestination);

if (forwardDestination == null)
{
Expand All @@ -95,7 +91,17 @@ protected async Task<bool> TryHandleDelayedMessage(Message message, SqlConnectio
}
catch (QueueNotFoundException e)
{
log.Error($"Message {message.TransportId} cannot be forwarded to its destination queue {e.Queue} because it does not exist.");
var hasEnclosedMessageTypeHeader = message.Headers.TryGetValue(Headers.EnclosedMessageTypes,
out var enclosedMessageTypeHeader);

if (hasEnclosedMessageTypeHeader)
{
log.ErrorFormat("Message with ID '{0}' of type '{1}' cannot be forwarded to its destination queue '{2}' because it does not exist.", message.TransportId, enclosedMessageTypeHeader, e.Queue);
}
else
{
log.ErrorFormat("Message with ID '{0}' cannot be forwarded to its destination queue '{1}' because it does not exist.", message.TransportId, e.Queue);
}

ExceptionHeaderHelper.SetExceptionHeaders(outgoingMessage.Headers, e);
outgoingMessage.Headers.Add(FaultsHeaderKeys.FailedQ, forwardDestination);
Expand Down

0 comments on commit 14c0f33

Please sign in to comment.