首页 > 解决方案 > 如何在 Azure Application Insights 中使用 BeginScope(在 https://portal.azure.com 中)?

问题描述

我的 C# 代码是log.BeginScope("Testing Scope1");log.BeginScope("Testing Scope2");. 如何在 Azure Application Insights 中使用(在https://portal.azure.com中)?

标签: azurescopeazure-application-insights

解决方案


如果您的代码如下所示:

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

然后,在代码执行后,导航到 azure 门户 -> 你的应用程序洞察 -> 日志 -> 在traces表中,编写以下查询(还要注意选择适当的“时间范围”):

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

截图如下:

在此处输入图像描述

顺便说一句,生成日志可能需要几分钟。并且请在您的应用程序中设置正确的日志级别(例如在您的 azure 函数中设置正确的日志级别)。


推荐阅读