我正在尝试让应用洞察在本地.NET 7 Worker Azure Function中工作
public class Tools
{
public Tools(ILoggerFactory loggerFactory)
{
_logger = loggerFactory.CreateLogger<Tools>();
}
[Function("test-app-insights")]
public async Task<IActionResult> TestAppInsightsAsync([HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "tools/test-app-insights")]
HttpRequest req)
{
_logger.LogInformation("HELLOFROMNEWFUNCTION");
await Task.Yield();
var response = 0;
var okResponse = new OkObjectResult(response);
return okResponse;
}
}
我已添加以下代码来配置服务,但App Insights中未显示任何内容,也未出现任何错误
var appInsightsConnectionString = "MY CONNECTION STRING";
services.AddApplicationInsightsTelemetryWorkerService((a =>
{
a.EnableAdaptiveSampling = false;
a.ConnectionString = appInsightsConnectionString;
}));
有人知道我错过了什么吗?
我在host.json的日志记录部分中有这个
"logging": {
"logLevel": {
"default": "Information",
"Microsoft": "Warning",
"System": "Warning",
"Host": "Error",
"Function": "Error",
"Host.Aggregator": "Information"
},
"Serilog": {
"MinimumLevel": "Information",
"WriteTo": [
{
"Name": "Console",
"Args": {
"outputTemplate": "{Timestamp:HH:mm:ss} {Level} | {RequestId} - {Message}{NewLine}{Exception}"
}
}
]
},
"applicationInsights": {
"samplingSettings": {
"isEnabled": true
}
}
},
保罗
1条答案
按热度按时间9jyewag01#
创建Application Insights示例并复制检测密钥以供以后使用。
创建一个
Function App
.创建函数应用程序时启用
Application Insights
选项。选择我们在上一步中创建的Application Insights。
ApplicationInsights
后,InstrumentationKey
将自动添加到Application Settings
中。我的
host.json
:我的
local.settings.json
:我在
Azure Application Insights
示例中的跟踪: