Azure-webjobs-sdk: WebJobs.Logging.ApplicationInsights package defines conflicting ILoggingBuilder.AddApplicationInsights() extension method

Created on 31 Mar 2019  路  1Comment  路  Source: Azure/azure-webjobs-sdk

The WebJobs.Logging.ApplicationInsights package defines an ILoggingBuilder.AddApplicationInsights() extension method that has the exact same signature as one defined in the Microsoft.Extensions.Logging.ApplicationInsights package. This results in a compiler error if you reference both packages and try to call the method:

https://github.com/Azure/azure-webjobs-sdk/blob/6930c4ea9ec78db12a05a2d0bf38cce42ab04e13/src/Microsoft.Azure.WebJobs.Logging.ApplicationInsights/Extensions/ApplicationInsightsLoggingBuilderExtensions.cs#L21

Repro steps

Create a new project and add the following nuget references:

    <PackageReference Include="Microsoft.Azure.WebJobs.Logging.ApplicationInsights" Version="3.0.5" />
    <PackageReference Include="Microsoft.Extensions.Logging.ApplicationInsights" Version="2.9.1" />

Then try to add ApplicationInsights logging with the following:

new HostBuilder().ConfigureLogging(logging => logging.AddApplicationInsights());

The compiler will now report the following error:

CS0121: The call is ambiguous between the following methods or properties: 'Microsoft.Extensions.Logging.ApplicationInsightsLoggingBuilderExtensions.AddApplicationInsights(Microsoft.Extensions.Logging.ILoggingBuilder)' and 'Microsoft.Extensions.Logging.ApplicationInsightsLoggingBuilderExtensions.AddApplicationInsights(Microsoft.Extensions.Logging.ILoggingBuilder)'

Suggested Fix

The WebJobs SDK should not be providing it's own conflicting implementation of an already established extension method from the ApplicationInsights SDK. Placing the WebJobs version of the extension method in a different namespace, or changing it's name to make it clear that it is the WebJobs version of the API would resolve the problem.

Most helpful comment

@kroymann I faced the same problem with NuGet v3.0.12 of Microsoft.Azure.WebJobs.Logging.ApplicationInsights, even without installing the other package.
Then I noticed there's a logging.AddApplicationInsightsWebJobs(); that should be used instead of logging.AddApplicationInsights(); using it solved the problem.
The way I found it though is not ideal, I clicked peak definition which took me to where the function is defined; there I noticed the obsolete attribute with the comment below.

    [Obsolete("Use AddApplicationInsightsWebJobs instead.", false)]
    public static ILoggingBuilder AddApplicationInsights(this ILoggingBuilder builder)
    {
      return builder.AddApplicationInsightsWebJobs();
    }

I think it should be more obvious

>All comments

@kroymann I faced the same problem with NuGet v3.0.12 of Microsoft.Azure.WebJobs.Logging.ApplicationInsights, even without installing the other package.
Then I noticed there's a logging.AddApplicationInsightsWebJobs(); that should be used instead of logging.AddApplicationInsights(); using it solved the problem.
The way I found it though is not ideal, I clicked peak definition which took me to where the function is defined; there I noticed the obsolete attribute with the comment below.

    [Obsolete("Use AddApplicationInsightsWebJobs instead.", false)]
    public static ILoggingBuilder AddApplicationInsights(this ILoggingBuilder builder)
    {
      return builder.AddApplicationInsightsWebJobs();
    }

I think it should be more obvious

Was this page helpful?
0 / 5 - 0 ratings