Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Change log formatter while hosting ASP.NET application in Docker

All console logs are being formatted with SimpleConsoleFormatter (until this setting is overridden) and the default output when running the ASP.NET app on Kestrel looks like following:

info: Microsoft.Hosting.Lifetime[14]
      Now listening on: https://localhost:7007

But when I am using Docker to host my app – it looks like the JsonConsoleFormatter is being used instead. It’s just my guess… But anyway, the output now looks like following:

docker-webapi-1       | {"EventId":14,"LogLevel":"Information","Category":"Microsoft.Hosting.Lifetime","Message":"Now listening on: https://[::]:443","State":{"Message":"Now listening on: https://[::]:443","address":"https://[::]:443","{OriginalFormat}":"Now listening on: {address}"}}

How can I make the Docker outputs look the same when I am just using Kestrel? Thanks.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

What I want to achieve when using Docker:

info: Microsoft.Hosting.Lifetime[14]
      Now listening on: https://[::]:443

>Solution :

The aspnet docker images set the environment variable Logging__Console__FormatterName to json because Microsoft think that most people that run .NET code in Docker containers prefer that format.

To get it back to Simple formatting, you need to set the environment variable to Simple by adding

ENV Logging__Console__FormatterName=Simple

somewhere in your Dockerfile.

There’s an open issue on Github about the change: https://github.com/dotnet/dotnet-docker/issues/3274

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading