.net TelemetryConfiguration配置显示Sonar问题,当我使用它的示例时

qncylg1j  于 2023-01-03  发布在  .NET
关注(0)|答案(1)|浏览(120)

当我使用TelemetryConfiguration示例来传递配置时,它会抛出一个声纳问题,如

'TelemetryConfiguration.TelemetryConfiguration(string)' is obsolete: 'InstrumentationKey based global ingestion is being deprecated. Use the default constructor and manually set TelemetryConfiguration.ConnectionString. See https://github.com/microsoft/ApplicationInsights-dotnet/issues/2560 for more details.' [SofyUtilCommon]csharp(CS0618)

我的代码:

public class AppInsightsService
{
     public static string InstrumentationKey => 
     AppSettings.ApplicationInsights.InstrumentationKey;

    /// <summary>The TelemetryConfiguration for application</summary>
    public static TelemetryConfiguration Configuration
    {
        get => configuration ??= new TelemetryConfiguration(InstrumentationKey);
        set => configuration = value;
    }
}
qxgroojn

qxgroojn1#

我尝试了下面的解决方案,它为我工作,也声纳没有显示任何错误。

public static string InstrumentationKey => AppSettings.ApplicationInsights.InstrumentationKey;
public static TelemetryConfiguration Configuration
    {
        get {
          configuration ??= new TelemetryConfiguration();
          configuration.ConnectionString = $"InstrumentationKey={InstrumentationKey}";
          return configuration;
        } 
        set => configuration = value;
    }

相关问题