LogLevel values not matching

simplify3000 1 Reputation point


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:



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,

A set of technologies in the .NET Framework for building web applications and XML web services.
4,124 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Zhi Lv - MSFT 32,006 Reputation points Microsoft Vendor

    Hi @simplify3000 ,

    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,

    0 comments No comments