Home > front end >  Azure function iLogger isEnabled is not picking up host.json
Azure function iLogger isEnabled is not picking up host.json

Time:01-22

I am trying to avoid executing the log.debug when the debug level is not enabled in the Azure function. When I execute the below code, the control goes within the IF block. Please explain why this is getting executed irrespective of the config in host.json file.

I tried creating another object using ILogger logger2 but still, it was the same.

[FunctionName("Function3")]
    public static async Task<IActionResult> Run(
        [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req,
        ILogger log)
    {
        log.LogInformation("C# HTTP trigger function processed a request.");

        log.LogCritical("*****From Function3******");


        log.LogTrace("LogTrace");
        if (log.IsEnabled(LogLevel.Debug))
        {
            //Control should not come inside this as the debug level is not enabled 

            log.LogDebug("Debug message inside debug level");//Not printed as expected.
            log.LogInformation("Inside Debug level"); //Not printed as expected
            log.LogError("LogError Inside Debug level"); //Printed because of the setting in host.json
        }
        log.LogDebug("LogDebug");
        log.LogInformation("LogInformation Blue");
        log.LogWarning("LogWarning Yellow");
        log.LogError("LogError Red");
        log.LogCritical("LogCritical White");

        return new OkObjectResult("Okay!");
    }

Host.JSON

{
  "version": "2.0",
  "logging": {
    "LogLevel": {
      "Default": "Warning",
      "Microsoft": "Warning",
      "Microsoft.Hosting.Lifetime": "Warning",
      "Function.Function3.User": "Error",
      "Function.PaymentFeeder.User": "Warning",
      "Function": "Warning"

    },
    "applicationInsights": {
      "samplingSettings": {
        "isEnabled": true,
        "excludedTypes": "Request"
      }
    }
  }
}

Update: Using Visual Studio 2022 and targeting.Net 6 Including the screenshot enter image description here

Using Debug logLevel for Function1

enter image description here

  •  Tags:  
  • Related