Reputation: 1309
I'm trying to setup Logging in my Azure Function App so that Azure App Insights only displays Information Level logs for a specific namespace, "TestNamespace" and its sub-namespaces, like "TestNamespace.Services.LogExample.Factory".
Setting the LogLevel default to "Trace" shows me everything in LogStream. Changing the default to "Error", keeping TestNamespace at "Information", the LogStream only shows errors.
I've read documentation, reviewed questions here and also asked ChatGPT but I can't find the reason. I ceated a Console App to test local logging but this behaves as expected.
Project v4 function in net8.0.
Program.cs contains
services.AddApplicationInsightsTelemetryWorkerService();
services.ConfigureFunctionsApplicationInsights();
Any advise what could be wrong in my host.json file?
{
"version": "2.0",
"logging": {
"logLevel": {
"default": "Error",
"Microsoft": "Error",
"Microsoft.Hosting.Lifetime": "Warning",
"TestNamespace": "Information",
"TestNamespace.*": "Information"
},
"applicationInsights": {
"samplingSettings": {
"isEnabled": false
},
"enableLiveMetricsFilters": true,
"enableDependencyTracking": true,
"enableDebugLogs": true
}
}
}
Upvotes: 0
Views: 136
Reputation: 11411
I ceated a Console App to test local logging but this behaves as expected. Azure AppInsights ignores LogLevel other namespaces for Azure Functions.
Yes, Azure Functions log level does not honor other namespace directions. It only honors if you specify a function using Function.Functionname
. Refer this Sample Json which explains what it accepts.
In Azure functions to change the default use Function.Functionname as below :
{
"version": "2.0",
"logging": {
"logLevel": {
"default": "Error",
"TestNamespace": "Information",
"Function.FunctionName": "Information"
}
}
}
Output:
After enabling application insights:
So, even you use Namespaces, default will only work. If your namespace is where you project resides then you can use Functionappname.Function
otherwise, you have to use function,functioname
Upvotes: 1