From 8753c6f86b522f8a387e5f0ffeef55e66764de5d Mon Sep 17 00:00:00 2001 From: Jezz Santos Date: Thu, 17 Oct 2024 07:56:25 +1300 Subject: [PATCH] Fixed runtime error when registering ApplicationInsights. Closes #53 --- .../Extensions/HostExtensions.cs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Infrastructure.Web.Hosting.Common/Extensions/HostExtensions.cs b/src/Infrastructure.Web.Hosting.Common/Extensions/HostExtensions.cs index 1608dda0..e90f1a54 100644 --- a/src/Infrastructure.Web.Hosting.Common/Extensions/HostExtensions.cs +++ b/src/Infrastructure.Web.Hosting.Common/Extensions/HostExtensions.cs @@ -71,6 +71,11 @@ public static WebApplication ConfigureApiHost(this WebApplicationBuilder appBuil WebHostOptions hostOptions) { var services = appBuilder.Services; +#if HOSTEDONAZURE + // HACK: We need to add this dependency before registering any keyed dependencies, for ApplicationInsights v2.22.0. + // See https://github.com/microsoft/ApplicationInsights-dotnet/issues/2879 + services.AddApplicationInsightsTelemetry(); +#endif RegisterSharedServices(); RegisterConfiguration(hostOptions.IsMultiTenanted); RegisterRecording(); @@ -171,8 +176,6 @@ void RegisterRecording() #else #if HOSTEDONAZURE loggingBuilder.AddApplicationInsights(); - - services.AddApplicationInsightsTelemetry(); #elif HOSTEDONAWS loggingBuilder.AddLambdaLogger(); #endif