azure-functions-dotnet-worker: Unable to overwrite log formatting into a console for Azure Function Isolated Host Worker
At the moment I can change the log format for function logging, but unfortunately cannot overwrite log formatting into a console for host, unlike the in-process function.
Steps to reproduce:
Prerequisites
- Linux docker container
- .NET 6 Isolated Function.
Program.csfile setup ⬇️
await new HostBuilder()
.ConfigureFunctionsWorkerDefaults(builder =>
{
builder.Services.AddLogging(provider =>
{
provider.ClearProviders();
provider.AddJsonConsole();
});
})
.ConfigureAppConfiguration(builder =>
{
builder.AddJsonFile("host.json");
builder.AddJsonFile("work.settings.json");
})
.ConfigureServices((context, services) =>
{
services.AddLogging(builder =>
{
});
})
.Build()
.RunAsync();
Actual log message in console:
info: Host.Function.Console[0]
{"EventId":0,"LogLevel":"Error","Category":"MyTestServiceFunc.HealthFunction","Message":"Test works perfectly :). Some random number: 550","State":{"Message":"Test works perfectly :). Some random number: 550","0":550,"{OriginalFormat}":"Test works perfectly :). Some random number: {0}"}}
Expected log message:
{"EventId":0,"LogLevel":"Error","Category":"MyTestServiceFunc.HealthFunction","Message":"Test works perfectly :). Some random number: 987","State":{"Message":"Test works perfectly :). Some random number: 987","0":987,"{OriginalFormat}":"Test works perfectly :). Some random number: {0}"}}
So the main difference is in this line: info: Host.Function.Console[0] which brakes our logging agent which reads logs from container console (stdout) in JSON format only.
About this issue
- Original URL
- State: open
- Created 3 years ago
- Reactions: 8
- Comments: 17 (4 by maintainers)
Guys, Any update on this? Were you able to carry out the necessary tests and verify the point in question?
@kAleksei thank you, that is helpful to understand your scenario. I am familiar with k8s log pattern like this and sounds like a solid reason for us to evaluate supporting this. Unfortunately, it won’t be possible now. But we have been discussing sweeping improvements for observability in Azure Functions and this can be considered as a part of it. There is no ETA on that and the work has not been started yet.
Hey, any comments on this?