Search code examples
azureloggingscopeazure-application-insights

Logging BeginScope with Azure Application Insights


My C# code uses the logging methods of BeginScope("Testing Scope1"); and BeginScope("Testing Scope2");.

How can those methods processes be seen in Azure Application Insights?


Solution

  • If your code like below:

            using (_logger.BeginScope("Testing Scope1"))
            {
                _logger.LogInformation("this is an info from index page 111111");
            }
    

    Then, after the code is executed, nav to azure portal -> your application insights -> Logs -> in the traces table, write the following query(also note that select a proper "time range"):

    traces
    | where customDimensions.Scope contains "Testing Scope1"
    | project message, customDimensions
    

    The screenshot is as below:

    enter image description here

    By the way, it may take a few minutes for the logs being generated. And please also set the proper log level in your application(like set the proper log level in your azure function).