使用Microsoft Extension Logging框架设置CustomDimensions

问题描述 投票:0回答:1

我已经为asp.net核心项目建立了应用程序见解。

appsettings.json:

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

Startup.cs:

services.AddApplicationInsightsTelemetry();

并且现在可以在我的控制器中登录:

Logger.LogDebug("LogDebug");

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

asp.net-core azure-application-insights microsoft-extensions-logging
1个回答
0
投票
[

例如,如果要在customDimentions中添加2个属性城市/用户,请在控制器中使用以下代码:

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

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

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.