'Setting the LOGGING__CONSOLE__FORMATTERNAME in aspnet6.0 image

How do I set this environment variable when I run a .NET 6.0 docker file?

I have a docker image based off aspnet6.0 Docker file. By default the environment variable is set as Json. I want to set it to Simple without changing the code.

The console log formatter is here: https://docs.microsoft.com/en-us/dotnet/core/extensions/console-log-formatter

Can this be done?

I thought it would as simple as:

docker run --env LOGGING__CONSOLE__FORMATTERNAME=Simple <CONTAINER_NAME> 

This does set an environment variable with this name. However it does not overwrite the environment variable it results in a duplicate setting. I would expect making the above command to overwrite the setting for: LOGGING__CONSOLE__FORMATTERNAME.

Therefore my console is still formatted as JSON and not in Simple format as I expect.



Solution 1:[1]

The reason is it not overriding the setting is the capitalisation should match the existing environment variable: Logging__Console__FormatterName

However the Docker container dotnet/aspnet has now reverted to the behaviour in 5.0 by not overriding the log format to JSON.

https://docs.microsoft.com/en-us/dotnet/core/compatibility/containers/6.0/console-formatter-default

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 dlaudams