add AppInsights ILogger sink

This commit is contained in:
Collin M. Barrett 2019-06-28 21:58:34 -05:00
parent 89848926bf
commit 91c6ba5513
2 changed files with 30 additions and 1 deletions

View file

@ -32,13 +32,25 @@
<PackageReference Include="LibGit2Sharp" Version="0.26.0" />
<PackageReference Include="MediatR" Version="7.0.0" />
<PackageReference Include="MediatR.Extensions.Microsoft.DependencyInjection" Version="7.0.0" />
<PackageReference Include="Microsoft.ApplicationInsights" Version="2.10.0" />
<PackageReference Include="Microsoft.ApplicationInsights.DependencyCollector" Version="2.10.0" />
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="2.9.3" />
<PackageReference Include="Microsoft.DotNet.Analyzers.Compatibility" Version="0.2.12-alpha" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="2.2.4" />
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.Http" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.Logging.ApplicationInsights" Version="2.10.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="2.2.0" />
<PackageReference Include="RestSharp" Version="106.6.9" />
</ItemGroup>
<ItemGroup>
<None Update="appsettings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>

View file

@ -1,10 +1,12 @@
using System;
using System.IO;
using System.Threading.Tasks;
using Autofac;
using Autofac.Extensions.DependencyInjection;
using FilterLists.Agent.Infrastructure;
using FilterLists.Agent.ListArchiver;
using MediatR;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
@ -26,10 +28,16 @@ public static async Task Main()
private static void RegisterServices()
{
var configuration = GetConfiguration();
var serviceCollection = new ServiceCollection();
// register Agent services
serviceCollection.AddLogging(b => b.AddConsole());
//serviceCollection.AddSingleton(configuration);
serviceCollection.AddLogging(b =>
{
b.AddConsole();
b.AddApplicationInsights(configuration["ApplicationInsights:InstrumentationKey"]);
});
serviceCollection.AddMediatR(typeof(Program).Assembly);
serviceCollection.AddHttpClient<AgentHttpClient>();
serviceCollection.AddSingleton<IFilterListsApiClient, FilterListsApiClient>();
@ -39,5 +47,14 @@ private static void RegisterServices()
var container = containerBuilder.Build();
_serviceProvider = new AutofacServiceProvider(container);
}
private static IConfigurationRoot GetConfiguration()
{
return new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json", true, false)
.AddEnvironmentVariables()
.Build();
}
}
}