Skip to content

Commit 6d2c1fc

Browse files
committed
Use structured logging for exceptions
1 parent d6aee2c commit 6d2c1fc

2 files changed

Lines changed: 3 additions & 3 deletions

File tree

src/BuildingBlocks/EventBus/EventBusRabbitMQ/DefaultRabbitMQPersisterConnection.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public bool TryConnect()
7272
.Or<BrokerUnreachableException>()
7373
.WaitAndRetry(_retryCount, retryAttempt => TimeSpan.FromSeconds(Math.Pow(2, retryAttempt)), (ex, time) =>
7474
{
75-
_logger.LogWarning(ex.ToString());
75+
_logger.LogWarning(ex, "RabbitMQ Client could not connect after {TimeOut}s ({ExceptionMessage})", $"{time.TotalSeconds:n1}", ex.Message);
7676
}
7777
);
7878

@@ -88,7 +88,7 @@ public bool TryConnect()
8888
_connection.CallbackException += OnCallbackException;
8989
_connection.ConnectionBlocked += OnConnectionBlocked;
9090

91-
_logger.LogInformation($"RabbitMQ persistent connection acquired a connection {_connection.Endpoint.HostName} and is subscribed to failure events");
91+
_logger.LogInformation("RabbitMQ acquired a persistent connection to '{HostName}' and is subscribed to failure events", _connection.Endpoint.HostName);
9292

9393
return true;
9494
}

src/BuildingBlocks/EventBus/EventBusRabbitMQ/EventBusRabbitMQ.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public void Publish(IntegrationEvent @event)
7676
.Or<SocketException>()
7777
.WaitAndRetry(_retryCount, retryAttempt => TimeSpan.FromSeconds(Math.Pow(2, retryAttempt)), (ex, time) =>
7878
{
79-
_logger.LogWarning(ex.ToString());
79+
_logger.LogWarning(ex, "Could not publish event: {EventId} after {Timeout}s ({ExceptionMessage})", @event.Id, $"{time.TotalSeconds:n1}", ex.Message);
8080
});
8181

8282
using (var channel = _persistentConnection.CreateModel())

0 commit comments

Comments
 (0)