refactor(AuthClient): Ausführlichere Protokollierung hinzufügen.

This commit is contained in:
Developer 02
2025-03-12 10:27:06 +01:00
parent d46dbbb877
commit 5f9efa3bb0
2 changed files with 11 additions and 4 deletions

View File

@@ -51,16 +51,23 @@ public class AuthClient : IAuthClient, IHostedService
await GetAllPublicKeysAsync();
}
private int nOfAttempts = 0;
private async Task<bool> TryStartConnectionAsync(CancellationToken cancellationToken = default)
{
try
{
nOfAttempts += 1;
await _connection.StartAsync(cancellationToken);
_logger?.LogInformation("Auth-client connection successful. Number of connection attempts {nOfAttempts}.", nOfAttempts);
return true;
}
catch(HttpRequestException ex)
{
_logger?.LogError(ex, "Connection is failed. {message}", ex.Message);
if (_params.RetryDelay is null)
_logger?.LogError(ex, "Auth-client connection failed. {message}", ex.Message);
else
_logger?.LogError(ex, "Auth-client connection failed and will be retried every {time} seconds. The status of being successful can be followed from the information logs.\n{message}", _params.RetryDelay.Value.TotalSeconds, ex.Message);
return false;
}
}