39 lines
1.2 KiB
C#
39 lines
1.2 KiB
C#
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;
|
|
}
|
|
}
|
|
} |