question

simplify3000-6685 avatar image
0 Votes"
simplify3000-6685 asked ZhiLv-MSFT answered

LogLevel values not matching

Hello,

Can you please advise why the values for LogLevel in Microsoft.Extensions.Logging,
do NOT match those in Microsoft.ApplicationInsights.DataContracts?

here is the code:

114743-ms-extensions-log-level.jpg


114725-appinsights-severity-level.jpg

So in my C# code, when I have the statement:

 //in the loglevel this is = 3
 logger.LogWarning("User does not have access");

I was expecting this to show up in Application Insights as 3, but instead it shows as 2.

This can sometimes lead to issues in interpreting logs and usage data.

would appreciate your advice,
thanks




dotnet-aspnet-core-webapi
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

ZhiLv-MSFT avatar image
0 Votes"
ZhiLv-MSFT answered

Hi @simplify3000-6685,

why the values for LogLevel in Microsoft.Extensions.Logging, do NOT match those in Microsoft.ApplicationInsights.DataContracts

They are two different packages, to the Microsoft.ApplicationInsights.DataContracts.SeverityLevel, it is used by ExceptionTelemetry and TraceTelemetry to identify severity level. And the LogLevel Enum defines logging severity levels.

From your code and description, I assume you want to enable Application Insights for an ASP.NET Core application and collect logs, right?

If that is the case, you should use the following package in the Asp.net Core application:

Then, it will use the Microsoft.Extensions.Logging.LogLevel to set the log level.

More detail information about using Application Insights with Asp.net Core application, see:

Application Insights for ASP.NET Core applications

Application Insights logging with .NET


If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

Best Regards,
Dillion

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.