0
votes

I have a asp.net core 2 application where i am trying to log traces using LoggerMessage extension methods.(https://docs.microsoft.com/en-us/aspnet/core/fundamentals/logging/loggermessage). The default trace level is set to trace. I am logging Critical,Errors,Warnings and Information messages. These appear on the console and the debug window. But are not reported to application insights.

I have Added ".UseApplicationInsights()" to the web host builder and added the "_loggerFactory.AddApplicationInsights(app.ApplicationServices, LogLevel.Trace);" to the startup. I have also ensure that the app insights key is set in the appsetting.json file.

"ApplicationInsights": { "InstrumentationKey": "XXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXX" }, Can someone help me with what am i missing?

SDK Version Microsoft.ApplicationInsights.AspNetCore - 2.1.1 Microsoft.AspNetCore.All - 2.0.5

1
UseApplicationInsights and AddApplicationInsights are mutually exclusive ways to set up Application Insights for your application. You need to choose only one way, in your case, remove UseApplicationInsights call in Program.cs - twinmind
Thanks @twinmind. That helped to resolve the issue. But it was the other way around. We had to remove "AddApplicationInsights". Removing "UseApplicationInsights" had not helped. - Gurpreet Singh

1 Answers

0
votes

Thanks @twinmind. That helped to resolve the issue. But it was the other way around. We had to remove "AddApplicationInsights". Removing "UseApplicationInsights" had not helped.