This commit is contained in:
2024-10-11 23:10:01 -05:00
parent 4137ac9ad8
commit 62a4a47373
6 changed files with 173 additions and 0 deletions

View File

@@ -0,0 +1,39 @@
using Microsoft.Extensions.Logging;
namespace ProperDI.Azure.Endpoints.ResourceGroup.LogLooker;
public interface IActivityLogReader
{
Task Scan(CancellationToken cancellationToken);
}
public class ActivityLogReader : IActivityLogReader
{
private readonly ILogger<ActivityLogReader> _logger;
private readonly HttpClient _httpClient;
public ActivityLogReader(IHttpClientFactory httpClientFactory, ILogger<ActivityLogReader> logger)
{
_httpClient = httpClientFactory.CreateClient() ?? throw new ArgumentNullException(nameof(httpClientFactory));
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
}
public async Task Scan(CancellationToken cancellationToken)
{
try
{
var response = await _httpClient.GetAsync("https://ident.me", cancellationToken);
var responseBody = await response.Content.ReadAsStringAsync();
_logger.LogInformation("Response body: {content}", responseBody);
}
catch (TaskCanceledException)
{
_logger.LogWarning("Task canceled");
}
catch (System.Exception ex)
{
_logger.LogError(ex, "Http request failed");
throw;
}
}
}