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.
What I want to achieve when using Docker:
info: Microsoft.Hosting.Lifetime[14]
Now listening on: https://[::]:443
CodePudding user response:
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