I am trying to get app insights to work in a local .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;
}
}
I have added the code below to configure services but nothing is shown in App Insights, and there are no errors
var appInsightsConnectionString = "MY CONNECTION STRING";
services.AddApplicationInsightsTelemetryWorkerService((a =>
{
a.EnableAdaptiveSampling = false;
a.ConnectionString = appInsightsConnectionString;
}));
Does anyone know what I have missed?
I have this in the logging section of my 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
}
}
},
Paul