Formatting Logging in .NET 5 for AKS Log Analytics

Jeroen VdB
1 min readOct 25, 2021

Today I was trying to investigate an issue in a Docker image running on Azure Kubernetes Serice (AKS). Because it was working on my machine, as usual, I had to look in the Log Analytics of our running pod which contains a fairly simple console app.
I noticed that the output of the logs was very unclear. Every new line was a new log entry and there wasn't even a log level, so I was not able to filter on errors only.

This made me fiddle around with the console log formatted.

See this GitHub Gist which formats the following result:

If you still want the default logging format local, you can of course override it with e.g. the appsettings.Development.json file.

For a quick copy/paste of the appsettings.json:

{ "Logging": { "LogLevel": { "Default": "Information", "Microsoft": "Warning", "Microsoft.Hosting.Lifetime": "Information" }, "Console": { "FormatterName": "json", "FormatterOptions": { "SingleLine": true } } } }

--

--

Jeroen VdB

Integration developer with a focus on Microsoft Azure.