Попробуйте код ниже, чтобы добавить переменную, чтобы указать, успешно ли reposne.
public async Task Send(CancellationToken token)
{
logger.LogInformation("E-mail background delivery started");
bool IsSuccess = false;
while (!token.IsCancellationRequested && !IsSuccess)
{
try
{
if (FullUrl != null)
{
var request = new HttpRequestMessage(HttpMethod.Get, FullUrl);
// Let's wait for a message to appear in the queue
// If the token gets canceled, then we'll stop waiting
// since an OperationCanceledException will be thrown
var client = _clientFactory.CreateClient();
// token.ThrowIfCancellationRequested();
var response = await client.SendAsync(request, token).ConfigureAwait(false);
if (!response.IsSuccessStatusCode)
{
logger.LogInformation($"E-mail sent to");
}
else
{
IsSuccess = true;
}
}
//as soon as a message is available, we'll send it
logger.LogInformation($"E-mail sent to");
}
catch (OperationCanceledException)
{
//We need to terminate the delivery, so we'll just break the while loop
break;
}
catch(Exception e)
{
#warning Implement a retry mechanism or else this message will be lost
logger.LogWarning($"Couldn't send an e-mail to");
break;
}
}
logger.LogInformation("E-mail background delivery stopped");
}