gpt4 book ai didi

azure - 使用 Microsoft 扩展日志记录框架设置 CustomDimensions

转载 作者:行者123 更新时间:2023-12-02 23:26:04 26 4
gpt4 key购买 nike

我已经为 ASP.NET Core 项目设置了应用程序洞察。

appsettings.json:

  "ApplicationInsights": {
"InstrumentationKey": "90f786b7-36a5-xxxx-b1fc-xxxxxxxxx"
},

启动.cs:

services.AddApplicationInsightsTelemetry();

在我的 Controller 中,我现在可以记录:

Logger.LogDebug("LogDebug");

我找不到任何有关如何设置 CustomDemensions 的信息。我可以在重载中看到有一个对象数组,但不确定是否适用于自定义维度。有什么指点吗?

最佳答案

更新:

            var dict = new Dictionary<string, object> { { "user_name","ivan"},{ "mycity","new york"} };

using (_logger.BeginScope(dict))
{
_logger.LogInformation("this is a test message for testing purpose 456");
}
<小时/>

原始答案:

例如,如果您想在 customDimentions 中添加 2 个属性 city/user,请在 Controller 中使用以下代码:

string city = "london";
string user = "jack";
_logger.LogInformation("{user} sends a message from {city}", user, city);

然后在 azure 门户 -> 应用程序洞察日志中:

enter image description here

关于azure - 使用 Microsoft 扩展日志记录框架设置 CustomDimensions,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61853098/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com