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 } } } }

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Jeroen VdB
Jeroen VdB

Written by Jeroen VdB

Integration developer with a focus on Microsoft Azure.

No responses yet

Write a response