A community member has associated this post with a similar question:
Azure Functions - Logging not working correctly in local

Only moderators can edit this content.

Azure Functions - Logging not working correctly in local

Singh, Rahul 1 Reputation point
2024-04-17T14:07:57.7333333+00:00

I have a simple dotnet-isolated Azure function written in .Net 8 which has 1 Http trigger function. I have another custom database logger which is added to this function to enable database logging.

When I am executing the function, none of the Microsoft related logging are getting filtered and it's logging hundreds of entries in my database. I have already tested my custom logger with a simple console application where the logging filtering works correctly. What's interesteing is apart from my own custom logger, the console logs are also not getting filtered.

This is how my Program.cs looks:-

var host = new HostBuilder()
    .ConfigureFunctionsWebApplication()
    .ConfigureAppConfiguration((context, builder) =>
    {
        builder.SetBasePath(Directory.GetCurrentDirectory())
               .AddJsonFile("local.settings.json", optional: true);
    })
           .ConfigureLogging((builder, logging) =>
               {
                   logging.AddConsole();
                   logging.AddDbLogger(options =>
                     {
                       builder.Configuration.GetSection("Database")
                              .GetSection("Options").Bind(options);
                           });
                       })
    .ConfigureServices(services =>
    {
        services.AddApplicationInsightsTelemetryWorkerService();
        services.ConfigureFunctionsApplicationInsights();
    })
    .Build();

I have added the resp. logging in host.json file:-

{
    "version": "2.0",
    "logging": {
      "applicationInsights": {
        "samplingSettings": {
          "isEnabled": true,
          "excludedTypes": "Request"
        },
        "enableLiveMetricsFilters": true
      },
      "logLevel": {
        "default": "Information",
        "Microsoft": "Error"
      },
      "Database": {
        "logLevel": {
          "default": "Error"
        }
      },
      "console": {
        "logLevel": {
          "default": "Error"
        }
      }
    }
}

Still it shows Log entries in Console and Database

enter image description here

User's image

Is there anything wrong with my host.json?

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
4,281 questions
Visual Studio
Visual Studio
A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.
4,614 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,264 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Ryan Hill 25,821 Reputation points Microsoft Employee
    2024-04-17T17:19:37.9466667+00:00

    Hi @Singh, Rahul, I see this is a duplicate post of https://learn.microsoft.com/en-us/answers/questions/1657156/azure-functions-logging-not-working-correctly-in-l so I will redirect this question to your original post.

    0 comments No comments