I am trying to find out what is wrong with my code or approach. I am using Azure Functions (v3) and use ILogger interface to log events from my functions. Here is the sample code I am using:
[FunctionName("GetVersion")]
public static async Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req,
ILogger log)
{
log.LogInformation("[TEST] this is informational");
log.LogDebug("[TEST] this is debug");
log.LogTrace("[TEST] this is trace");
return new OkResult();
}
My Azure Functions have Application Insights are enabled, so logs are written to the traces table, and I can query for them like this:
traces
| order by timestamp
| where operation_Name == 'GetVersion'
| project timestamp,message,severityLevel
| limit 200
But the result looks like this (columns are timestamp, message and the last one is log severity level):
The problems I have are that:
- Severity both for Trace and Debug logs is 0, while they should have distinct levels.
- Actual severity levels differ from MS documentation. Trace should be 0 and Debug 1 https://docs.microsoft.com/en-us/dotnet/api/microsoft.extensions.logging.loglevel?view=dotnet-plat-ext-3.1
Expected behavior is that severity in App Insights matches severity levels from documentation. What am I missing here?
P.S. My host.json looks like this
{
"version": "2.0",
"logging": {
"applicationInsights": {
"samplingExcludedTypes": "Request",
"samplingSettings": {
"isEnabled": true
}
},
"logLevel": {
"default": "Information",
"Host.Results": "Information",
"Function": "Debug",
"Function.GetVersion": "Trace",
"Host.Aggregator": "Trace"
}
}
}