I'm using AzureFunctionsVersion-4 in dotnet-isolated mode with dotnet-8!
I'm using the Default logging provider in dotnet.
I have a problem with logging! the problem is, that I have an HTTP call with HttpClient to an external service and there are some logs there like the one below:
Executing '[FunctionName]' (Reason='New queue message detected on 'queueName'.', Id=e29a273f-4181-4f59-a523-374639efc066)
Start processing HTTP request GET [Endpoint]
Sending HTTP request GET [Endpoint]
Received HTTP response headers after *ms - 200
End processing HTTP request after *ms - 200
Executed '[FunctionName]' (Succeeded, Id=e29a273f-4181-4f59-a523-374639efc066, Duration=*ms)
I did everything to get these logs disabled but did not work!
here are the configurations in host.json:
{
"version": "2.0",
"logging": {
"logLevel": {
"Microsoft": "Warning"
}
},
"extensions": {
"queues": {
"batchSize": 5
}
}
}
and in the appsettings.json:
"Logging": {
"LogLevel": {
"Default": "Warning",
"FunctionName": "Information"
}
}
I was trying to add "Function": "Warning" in host.json for the "Executing/Executed" logs but It has disabled all of the other logs in the whole of the function!
here is the function code:
using System.IO.Compression;
using System.Text;
using Microsoft.Azure.Functions.Worker;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
namespace FunctionName.Sample.Functions;
public class TestFunction
{
private readonly ILogger<TestFunction> _logger;
private readonly IHttpService _httpService;
public TestFunction(
ILogger<TestFunction> logger,
IHttpService httpService
)
{
_logger = logger;
_httpService = httpService;
}
[Function(nameof(TestFunction))]
public async Task RunAsync([QueueTrigger("%QueueName%")] byte[] bytes, CancellationToken cancellationToken)
{
try
{
_logger.LogInformation("Logs...");
var result = await _httpService.Call(cancellationToken);
_logger.LogInformation($"C# Queue trigger function processed.");
}
catch (Exception ex)
{
throw;
}
}
}
var host = new HostBuilder()
.ConfigureFunctionsWorkerDefaults()
.ConfigureServices((builder, services) =>
{
// ...
var configuration = builder.Configuration;
// ...
})
.ConfigureAppConfiguration((context, builder) =>
{
builder.ConfigureApp(context); // Add ENV variables here
})
.Build();
host.Run();
The point here is that the same configuration is working properly in the dotnet-6 project!
Does anyone have any opinion here?
I have created Queue trigger function with runtime stack dotnet isolated 8.0.
.ConfigureLogging(logging =>
{
logging.Services.Configure<LoggerFilterOptions>(options =>
{
LoggerFilterRule defaultRule = options.Rules.FirstOrDefault(rule => rule.ProviderName
== "Microsoft.Extensions.Logging.ApplicationInsights.ApplicationInsightsLoggerProvider");
if (defaultRule is not null)
{
options.Rules.Remove(defaultRule);
}
});
})
Function code:
namespace FunctionApp1
{
public class Function1
{
private readonly ILogger<Function1> _logger;
public Function1(ILogger<Function1> logger)
{
_logger = logger;
}
[Function("Function1")]
public IActionResult Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post")] HttpRequest req)
{
_logger.LogInformation("C# HTTP trigger function processed a request.");
_logger.LogInformation("This is Information log");
_logger.LogWarning("This is Warning log");
_logger.LogError("This is Error log");
_logger.LogCritical("This is Critical log");
return new OkObjectResult("Welcome to Azure Functions!");
}
}
}
Warning severity level by default. You need to disable it in part of service configuration in program.cs below:Program.cs:
var host = new HostBuilder()
.ConfigureFunctionsWebApplication()
.ConfigureServices(services =>
{
services.AddApplicationInsightsTelemetryWorkerService();
services.ConfigureFunctionsApplicationInsights();
})
.ConfigureLogging(logging =>
{
logging.Services.Configure<LoggerFilterOptions>(options =>
{
LoggerFilterRule defaultRule = options.Rules.FirstOrDefault(rule => rule.ProviderName
== "Microsoft.Extensions.Logging.ApplicationInsights.ApplicationInsightsLoggerProvider");
if (defaultRule is not null)
{
options.Rules.Remove(defaultRule);
}
});
})
.Build();
host.Run();
In Isolated function give the logging level for function and default are seperately in host.json. check below:
Host.json:
{
"version": "2.0",
"logging": {
"logLevel": {
"Microsoft": "Warning",
"Function": "Information"
},
"applicationInsights": {
"samplingSettings": {
"isEnabled": false,
"excludedTypes": "Request"
},
"enableLiveMetricsFilters": true
}
},
}
I have successfully deployed the function into azure portal. Then got triggered and getting logs. check below:

Output:

Only working solution I have found which disables HttpClient logging:
var host = new HostBuilder()
.ConfigureFunctionsWebApplication()
.ConfigureLogging(
logging =>
{
// Disable IHttpClientFactory Informational logs.
logging.AddFilter("System.Net.Http.HttpClient", LogLevel.Warning);
})
.Build();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With