mirror of
https://github.com/collinbarrett/FilterLists.git
synced 2026-03-11 09:04:27 +00:00
refactor(archival): 🔥 rm unnecessary explicit logging flush
This commit is contained in:
parent
da0806da59
commit
d2b29d4752
3 changed files with 2 additions and 54 deletions
|
|
@ -1,6 +1,5 @@
|
|||
using System;
|
||||
using FilterLists.Archival.Infrastructure.Clients;
|
||||
using FilterLists.Archival.Infrastructure.Logging;
|
||||
using FilterLists.Archival.Infrastructure.Persistence;
|
||||
using FilterLists.Archival.Infrastructure.Scheduling;
|
||||
using FilterLists.Directory.Api.Contracts;
|
||||
|
|
@ -23,7 +22,7 @@ public static void AddInfrastructureServices(this IServiceCollection services, I
|
|||
{
|
||||
_ = configuration ?? throw new ArgumentNullException(nameof(configuration));
|
||||
|
||||
services.AddArchivalLogging(configuration);
|
||||
services.AddSharedKernelLogging(configuration);
|
||||
services.AddSchedulingServices(configuration);
|
||||
services.AddDirectoryApiClient(configuration);
|
||||
services.AddClients();
|
||||
|
|
@ -32,7 +31,7 @@ public static void AddInfrastructureServices(this IServiceCollection services, I
|
|||
|
||||
public static void UseInfrastructure(this IApplicationBuilder app)
|
||||
{
|
||||
app.UseArchivalLogging();
|
||||
app.UseLogging();
|
||||
app.UseScheduling();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,22 +0,0 @@
|
|||
using FilterLists.SharedKernel.Logging;
|
||||
using MediatR.Pipeline;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace FilterLists.Archival.Infrastructure.Logging
|
||||
{
|
||||
internal static class ConfigurationExtensions
|
||||
{
|
||||
public static void AddArchivalLogging(this IServiceCollection services, IConfiguration configuration)
|
||||
{
|
||||
services.AddSharedKernelLogging(configuration);
|
||||
services.AddTransient(typeof(IRequestPostProcessor<,>), typeof(TelemetryClientFlushPostProcessor<,>));
|
||||
}
|
||||
|
||||
public static void UseArchivalLogging(this IApplicationBuilder app)
|
||||
{
|
||||
app.UseLogging();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,29 +0,0 @@
|
|||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using MediatR.Pipeline;
|
||||
using Microsoft.ApplicationInsights;
|
||||
|
||||
namespace FilterLists.Archival.Infrastructure.Logging
|
||||
{
|
||||
/// <remarks>https://docs.microsoft.com/en-us/azure/azure-monitor/app/api-custom-events-metrics#flushing-data</remarks>
|
||||
public class TelemetryClientFlushPostProcessor<TRequest, TResponse> : IRequestPostProcessor<TRequest, TResponse>
|
||||
where TRequest : notnull
|
||||
{
|
||||
private readonly TelemetryClient _telemetryClient;
|
||||
|
||||
public TelemetryClientFlushPostProcessor(TelemetryClient telemetryClient)
|
||||
{
|
||||
_telemetryClient = telemetryClient;
|
||||
}
|
||||
|
||||
public Task Process(TRequest request, TResponse response, CancellationToken cancellationToken)
|
||||
{
|
||||
_telemetryClient.Flush();
|
||||
|
||||
// Allow some time for flushing before shutdown.
|
||||
Thread.Sleep(5000);
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue