如何在Azure Application Insights(中)中使用BeginScopehttps://portal.azure.com)?

如何在Azure Application Insights(中)中使用BeginScopehttps://portal.azure.com)?,azure,scope,azure-application-insights,Azure,Scope,Azure Application Insights,我的C代码是log.BeginScopeTesting Scope1;和log.BeginScopeTesting Scope2;。如何在中的Azure Application Insights中使用?如果您的代码如下所示: using (_logger.BeginScope("Testing Scope1")) { _logger.LogInformation("this is an info from in

我的C代码是log.BeginScopeTesting Scope1;和log.BeginScopeTesting Scope2;。如何在中的Azure Application Insights中使用?

如果您的代码如下所示:

        using (_logger.BeginScope("Testing Scope1"))
        {
            _logger.LogInformation("this is an info from index page 111111");
        }
然后,在代码执行后,导航到azure门户->应用程序洞察->日志->在跟踪表中,编写以下查询并注意选择适当的时间范围:

traces
| where customDimensions.Scope contains "Testing Scope1"
| project message, customDimensions
截图如下:


顺便说一下,生成日志可能需要几分钟的时间。如果您的代码如下所示,请在应用程序中设置适当的日志级别

        using (_logger.BeginScope("Testing Scope1"))
        {
            _logger.LogInformation("this is an info from index page 111111");
        }
然后,在代码执行后,导航到azure门户->应用程序洞察->日志->在跟踪表中,编写以下查询并注意选择适当的时间范围:

traces
| where customDimensions.Scope contains "Testing Scope1"
| project message, customDimensions
截图如下:


顺便说一下,生成日志可能需要几分钟的时间。请在应用程序中设置适当的日志级别,如。

您真正的问题是什么?直接在using语句中使用它们,看。嗨@IvanYang,我想在中看到它,你能建议吗?谢谢。只需在azure portal中检查这些作用域?您的项目是什么?一个web项目?您好@IvanYang,您可以指导我从Azure函数/应用程序洞察日志中查找beginScope Testing Scope1的步骤吗?类似Testing Scope1的范围值将是log.beginScope中消息的自定义属性。例如,在代码usinglog.BeginScopetesting scope1{log.LogErrorthis is error;}中,然后在azure portal->your application insights中,您应该在跟踪表->中找到消息this is a error,然后在customDimensions列中,您可以看到范围。您真正的问题是什么?直接在using语句中使用它们,看。嗨@IvanYang,我想在中看到它,你能建议吗?谢谢。只需在azure portal中检查这些作用域?您的项目是什么?一个web项目?您好@IvanYang,您可以指导我从Azure函数/应用程序洞察日志中查找beginScope Testing Scope1的步骤吗?类似Testing Scope1的范围值将是log.beginScope中消息的自定义属性。例如,在代码usinglog.BeginScopetesting scope1{log.LogError这是一个错误;}中,然后在azure portal->your application insights中,您应该在跟踪表->中找到消息这是一个错误,然后在customDimensions列中,您可以看到范围。谢谢@Ivan Yang!但是当我使用traces | where isnotnullcustomDimensions.Scope时,没有返回结果。我的代码是log.BeginScopeTesting Scope1;然后log.LogInformationTest Info;。是因为我没有使用using,所以搜索结果没有结果吗?@DaiKeung,是的,请添加using,然后像我在答案中那样在using块中写入代码。谢谢@Ivan Yang!但是当我使用traces | where isnotnullcustomDimensions.Scope时,没有返回结果。我的代码是log.BeginScopeTesting Scope1;然后log.LogInformationTest Info;。是因为我没有使用using,所以搜索结果没有结果吗?@Daikeng,是的,请添加using,然后像我在答案中那样在using块中写入代码。