skip to Main Content

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

2

Answers


  1. Chosen as BEST ANSWER

    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


  2. This is my very basic host.json that works for my azure functions. Take it from here and try to adapt it by adding slowly your configuration and see where it stops working.

    {
    "version": "2.0",
    "logging": {
        "applicationInsights": {
            "samplingSettings": {
                "isEnabled": true,
                "excludedTypes": "Request"
            },
            "enableLiveMetricsFilters": true
          }
       }
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search