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:
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)'
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.
@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
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 oflogging.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.
I think it should be more obvious