1
0
Форкнуть 0

Add UseApplicationInsights() Extension methods on IHostBuilder.

This commit is contained in:
Cijo Thomas 2019-06-28 17:22:48 -07:00
Родитель d1e2620ea7
Коммит 92efcde157
3 изменённых файлов: 38 добавлений и 2 удалений

Просмотреть файл

@ -3,6 +3,7 @@
## Version 2.8.0-beta1
- [Fix: Add `IJavaScriptSnippet` service interface and update the `IServiceCollection` extension to register it for `JavaScriptSnippet`.](https://github.com/microsoft/ApplicationInsights-aspnetcore/issues/890)
- [Fix - ApplicationInsights StartupFilter should not swallow exceptions from downstream ApplicationBuilder.](https://github.com/microsoft/ApplicationInsights-aspnetcore/issues/897)
- [Add UseApplicationInsights() Extension methods on IHostBuilder](https://github.com/microsoft/ApplicationInsights-aspnetcore/pull/908)
## Version 2.7.0
- Updated Web/Base SDK version dependency to 2.10.0

Просмотреть файл

@ -3,6 +3,9 @@
using Microsoft.ApplicationInsights.AspNetCore.Extensions;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
#if NETSTANDARD2_0
using Microsoft.Extensions.Hosting;
#endif
using Microsoft.Extensions.Options;
/// <summary>
@ -25,6 +28,23 @@
return webHostBuilder;
}
#if NETSTANDARD2_0
/// <summary>
/// Configures <see cref="IHostBuilder"/> to use Application Insights services.
/// </summary>
/// <param name="hostBuilder">The <see cref="IHostBuilder"/> instance.</param>
/// <returns>The <see cref="IHostBuilder"/>.</returns>
public static IHostBuilder UseApplicationInsights(this IHostBuilder hostBuilder)
{
hostBuilder.ConfigureServices(collection =>
{
collection.AddApplicationInsightsTelemetry();
});
return hostBuilder;
}
#endif
/// <summary>
/// Configures <see cref="IWebHostBuilder"/> to use Application Insights services.
/// </summary>
@ -36,5 +56,19 @@
webHostBuilder.ConfigureServices(collection => collection.AddApplicationInsightsTelemetry(instrumentationKey));
return webHostBuilder;
}
#if NETSTANDARD2_0
/// <summary>
/// Configures <see cref="IHostBuilder"/> to use Application Insights services.
/// </summary>
/// <param name="hostBuilder">The <see cref="IHostBuilder"/> instance.</param>
/// <param name="instrumentationKey">Instrumentation key to use for telemetry.</param>
/// <returns>The <see cref="IHostBuilder"/>.</returns>
public static IHostBuilder UseApplicationInsights(this IHostBuilder hostBuilder, string instrumentationKey)
{
hostBuilder.ConfigureServices(collection => collection.AddApplicationInsightsTelemetry(instrumentationKey));
return hostBuilder;
}
#endif
}
}

Просмотреть файл

@ -75,6 +75,7 @@
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' ">
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.1.0" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.Logging.ApplicationInsights" Version="2.10.0" />
<PackageReference Include="System.Text.Encodings.Web" Version="4.3.1" />
</ItemGroup>