Search code examples
azureazure-functionsazure-functions-isolated

Azure Function : no logging after upgrading to .NET 8


I have upgraded my Azure functions to .NET 8. Since upgrading I no longer see any of my _logger.LogInformation events. Only errors get logged

I have reviewed this document (How to configure monitoring for Azure Functions) and adjusted my host.json accordingly. https://learn.microsoft.com/en-us/azure/azure-functions/configure-monitoring?tabs=v2

enter image description here

This is my host.json file

{
  "version": "2.0",
  "logging": {
    "fileLoggingMode": "always",
    "logLevel": {
      "default": "Information",
      "Function.IngressWebContent": "Information",
      "Function.IngressWebContent.User": "Information",
      "Host.Aggregator": "Information",
      "Host.Results": "Information",
      "Function": "Information"
    }
  }
}

These are the relevant parts of my code:

public class IngressWebContentFunction
{
    private readonly ILogger _logger;
    private readonly ILoggerFactory _loggerFactory;

    public IngressWebContentFunction(ILoggerFactory loggerFactory)
    {
        _logger = loggerFactory.CreateLogger<IngressWebContentFunction>();
        _loggerFactory = loggerFactory;
    }

[Function("IngressWebContent")]
public async Task<HttpResponseData> Run([HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequestData req, string hostname)
{
    _logger.LogInformation("I cannot see the message in the portal");
    // ...
}

I have tried different logging levels but that makes no difference

_logger.LogTrace("LogTrace");
_logger.LogDebug("LogDebug");

When I run the functions locally, I do see my events


Solution

  • I got the issue resolved by replacing my Program.cs with this. [1]

    A code comment in the file says: The Application Insights SDK adds a default logging filter that instructs ILogger to capture only Warning and more severe logs. Application Insights requires an explicit override.

    [1] https://github.com/Azure/azure-functions-dotnet-worker/blob/main/samples/FunctionApp/Program.cs