mirror of
https://github.com/collinbarrett/FilterLists.git
synced 2026-03-11 09:04:27 +00:00
use di container for logger
This commit is contained in:
parent
078c86ecd8
commit
ea03226b9c
4 changed files with 18 additions and 14 deletions
|
|
@ -1,7 +1,9 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
using FilterLists.Services;
|
||||
using FilterLists.Services.DependencyInjection.Extensions;
|
||||
using FilterLists.Services.Extensions;
|
||||
using FilterLists.Services.Snapshot;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
|
@ -11,7 +13,6 @@ namespace FilterLists.Agent
|
|||
public static class Program
|
||||
{
|
||||
private const int BatchSize = 1;
|
||||
private const string AppInsightsKeyConfig = "ApplicationInsights:InstrumentationKey";
|
||||
private static IConfigurationRoot configRoot;
|
||||
private static ServiceProvider serviceProvider;
|
||||
private static SnapshotService snapshotService;
|
||||
|
|
@ -23,6 +24,7 @@ public static async Task Main()
|
|||
BuildConfigRoot();
|
||||
BuildServiceProvider();
|
||||
snapshotService = serviceProvider.GetService<SnapshotService>();
|
||||
logger = serviceProvider.GetService<Logger>();
|
||||
await TryCaptureSnapshots();
|
||||
}
|
||||
|
||||
|
|
@ -41,16 +43,13 @@ private static void BuildServiceProvider()
|
|||
|
||||
private static async Task TryCaptureSnapshots()
|
||||
{
|
||||
using (logger = new Logger(configRoot[AppInsightsKeyConfig]))
|
||||
try
|
||||
{
|
||||
try
|
||||
{
|
||||
await CaptureSnapshots(BatchSize).TimeoutAfter(Timeout);
|
||||
}
|
||||
catch (TimeoutException te)
|
||||
{
|
||||
logger.Log(te);
|
||||
}
|
||||
await CaptureSnapshots(BatchSize).TimeoutAfter(Timeout);
|
||||
}
|
||||
catch (TimeoutException te)
|
||||
{
|
||||
logger.Log(te);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@ public static void AddFilterListsAgentServices(this IServiceCollection services,
|
|||
o.UseMySql(config.GetConnectionString("FilterListsConnection"),
|
||||
m => m.MigrationsAssembly("FilterLists.Api")));
|
||||
services.TryAddScoped<SnapshotService>();
|
||||
services.TryAddScoped<Logger>();
|
||||
services.AddAutoMapper();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FilterLists.Agent
|
||||
namespace FilterLists.Services.Extensions
|
||||
{
|
||||
public static class TaskExtensions
|
||||
{
|
||||
|
|
@ -1,17 +1,21 @@
|
|||
using System;
|
||||
using System.Threading;
|
||||
using JetBrains.Annotations;
|
||||
using Microsoft.ApplicationInsights;
|
||||
using Microsoft.ApplicationInsights.Extensibility;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
|
||||
namespace FilterLists.Agent
|
||||
namespace FilterLists.Services
|
||||
{
|
||||
[UsedImplicitly]
|
||||
public class Logger : IDisposable
|
||||
{
|
||||
private const string AppInsightsKeyConfig = "ApplicationInsights:InstrumentationKey";
|
||||
private readonly TelemetryClient telemetryClient;
|
||||
|
||||
public Logger(string appInsightsKey)
|
||||
public Logger(IConfiguration config)
|
||||
{
|
||||
TelemetryConfiguration.Active.InstrumentationKey = appInsightsKey;
|
||||
TelemetryConfiguration.Active.InstrumentationKey = config[AppInsightsKeyConfig];
|
||||
telemetryClient = new TelemetryClient();
|
||||
}
|
||||
|
||||
Loading…
Reference in a new issue