From c95ad55fd1a7edd91f8c45413a600aa9e606619b Mon Sep 17 00:00:00 2001 From: Timothy Mothra Lee Date: Tue, 25 May 2021 14:02:04 -0700 Subject: [PATCH 1/2] cleanup frameworks in AspNetCore --- .../ApplicationInsightsExtensions.cs | 2 -- ...licationInsightsServiceConfigureOptions.cs | 2 -- .../Extensions/RequestCollectionOptions.cs | 4 ---- .../ApplicationInsightsLogger.cs | 2 +- .../ApplicationInsightsLoggerProvider.cs | 9 ++++---- ...soft.ApplicationInsights.AspNetCore.csproj | 2 +- .../SdkVersionUtils.cs | 2 +- .../ApplicationInsightsExtensions.cs | 6 ----- ...ainNameRoleInstanceTelemetryInitializer.cs | 2 +- .../AddApplicationInsightsTelemetryTests.cs | 23 ------------------- .../BaseTestClass.cs | 7 ++---- .../ApplicationInsightsServiceOptionsTests.cs | 22 +----------------- ...pplicationInsights.AspNetCore.Tests.csproj | 6 ----- .../SdkVersionTestUtils.cs | 2 +- ...meRoleInstanceTelemetryInitializerTests.cs | 2 +- 15 files changed, 14 insertions(+), 79 deletions(-) diff --git a/NETCORE/src/Microsoft.ApplicationInsights.AspNetCore/Extensions/ApplicationInsightsExtensions.cs b/NETCORE/src/Microsoft.ApplicationInsights.AspNetCore/Extensions/ApplicationInsightsExtensions.cs index a085df0c55..8f8c750b8e 100644 --- a/NETCORE/src/Microsoft.ApplicationInsights.AspNetCore/Extensions/ApplicationInsightsExtensions.cs +++ b/NETCORE/src/Microsoft.ApplicationInsights.AspNetCore/Extensions/ApplicationInsightsExtensions.cs @@ -150,9 +150,7 @@ public static IServiceCollection AddApplicationInsightsTelemetry(this IServiceCo // NetStandard2.0 has a package reference to Microsoft.Extensions.Logging.ApplicationInsights, and // enables ApplicationInsightsLoggerProvider by default. -#if NETSTANDARD2_0 || NET461 AddApplicationInsightsLoggerProvider(services); -#endif } return services; diff --git a/NETCORE/src/Microsoft.ApplicationInsights.AspNetCore/Extensions/DefaultApplicationInsightsServiceConfigureOptions.cs b/NETCORE/src/Microsoft.ApplicationInsights.AspNetCore/Extensions/DefaultApplicationInsightsServiceConfigureOptions.cs index 62ba60da39..e1308b1955 100644 --- a/NETCORE/src/Microsoft.ApplicationInsights.AspNetCore/Extensions/DefaultApplicationInsightsServiceConfigureOptions.cs +++ b/NETCORE/src/Microsoft.ApplicationInsights.AspNetCore/Extensions/DefaultApplicationInsightsServiceConfigureOptions.cs @@ -33,12 +33,10 @@ public void Configure(ApplicationInsightsServiceOptions options) { var configBuilder = new ConfigurationBuilder() .SetBasePath(this.hostingEnvironment.ContentRootPath ?? Directory.GetCurrentDirectory()); -#if NETSTANDARD2_0 || NET461 if (this.userConfiguration != null) { configBuilder.AddConfiguration(this.userConfiguration); } -#endif configBuilder.AddJsonFile("appsettings.json", true) .AddJsonFile(string.Format(CultureInfo.InvariantCulture, "appsettings.{0}.json", this.hostingEnvironment.EnvironmentName), true) .AddEnvironmentVariables(); diff --git a/NETCORE/src/Microsoft.ApplicationInsights.AspNetCore/Extensions/RequestCollectionOptions.cs b/NETCORE/src/Microsoft.ApplicationInsights.AspNetCore/Extensions/RequestCollectionOptions.cs index f815698a99..d327830c47 100644 --- a/NETCORE/src/Microsoft.ApplicationInsights.AspNetCore/Extensions/RequestCollectionOptions.cs +++ b/NETCORE/src/Microsoft.ApplicationInsights.AspNetCore/Extensions/RequestCollectionOptions.cs @@ -17,11 +17,7 @@ public RequestCollectionOptions() // In NetStandard20, ApplicationInsightsLoggerProvider is enabled by default, // which captures Exceptions. Disabling it in RequestCollectionModule to avoid duplication. -#if NETSTANDARD2_0 || NET461 this.TrackExceptions = false; -#else - this.TrackExceptions = true; -#endif } /// diff --git a/NETCORE/src/Microsoft.ApplicationInsights.AspNetCore/Logging/Implementation/ApplicationInsightsLogger.cs b/NETCORE/src/Microsoft.ApplicationInsights.AspNetCore/Logging/Implementation/ApplicationInsightsLogger.cs index 6545cf0ee6..c2769bdf67 100644 --- a/NETCORE/src/Microsoft.ApplicationInsights.AspNetCore/Logging/Implementation/ApplicationInsightsLogger.cs +++ b/NETCORE/src/Microsoft.ApplicationInsights.AspNetCore/Logging/Implementation/ApplicationInsightsLogger.cs @@ -19,7 +19,7 @@ [SuppressMessage("Documentation Rules", "SA1614:ElementParameterDocumentationMustHaveText", Justification = "This class is obsolete and will not be completely documented.")] internal class ApplicationInsightsLogger : ILogger { -#if NET461 +#if NETFRAMEWORK /// /// SDK Version Prefix. /// diff --git a/NETCORE/src/Microsoft.ApplicationInsights.AspNetCore/Logging/Implementation/ApplicationInsightsLoggerProvider.cs b/NETCORE/src/Microsoft.ApplicationInsights.AspNetCore/Logging/Implementation/ApplicationInsightsLoggerProvider.cs index 9885a2a103..59d321280f 100644 --- a/NETCORE/src/Microsoft.ApplicationInsights.AspNetCore/Logging/Implementation/ApplicationInsightsLoggerProvider.cs +++ b/NETCORE/src/Microsoft.ApplicationInsights.AspNetCore/Logging/Implementation/ApplicationInsightsLoggerProvider.cs @@ -9,11 +9,12 @@ /// /// implementation that creates returns instances of . /// -#if !NETSTANDARD2_0 && !NET461 - // For NETSTANDARD2.0 and NET461 We take dependency on Microsoft.Extensions.Logging.ApplicationInsights which has ApplicationInsightsProvider having the same ProviderAlias and don't want to clash with this ProviderAlias. - [ProviderAlias("ApplicationInsights")] -#endif + /// + /// THIS CLASS IS OBSOLETE. + /// For NETSTANDARD2.0 and NET461 We take dependency on Microsoft.Extensions.Logging.ApplicationInsights which has ApplicationInsightsProvider having the same ProviderAlias and don't want to clash with this ProviderAlias. + /// [SuppressMessage("Documentation Rules", "SA1614:ElementParameterDocumentationMustHaveText", Justification = "This class is obsolete and will not be completely documented.")] + [Obsolete] internal class ApplicationInsightsLoggerProvider : ILoggerProvider { private readonly TelemetryClient telemetryClient; diff --git a/NETCORE/src/Microsoft.ApplicationInsights.AspNetCore/Microsoft.ApplicationInsights.AspNetCore.csproj b/NETCORE/src/Microsoft.ApplicationInsights.AspNetCore/Microsoft.ApplicationInsights.AspNetCore.csproj index c5cff312b8..83bd6d100f 100644 --- a/NETCORE/src/Microsoft.ApplicationInsights.AspNetCore/Microsoft.ApplicationInsights.AspNetCore.csproj +++ b/NETCORE/src/Microsoft.ApplicationInsights.AspNetCore/Microsoft.ApplicationInsights.AspNetCore.csproj @@ -37,7 +37,7 @@ - +