Setting Dotnet Log Level Using Environment Variables
After migrating a bunch of old Dotnet applications from Azure Web Apps on Windows to Docker containers on Linux, I found that the logs were flooded by Information messages from Dotnet itself. Instead of fiddling with JSON files, you can set the log level using environment variables. I guess it’s a matter of preference, but I don’t see a value of having this tracked by version control and setting environment variables and reloading a service’s containers, is very straight forward in our own infrastructure at work.
So, this is an example of how the log levels can be set granularly using envs.
LOGGING__LOGLEVEL__DEFAULT=Information
LOGGING__LOGLEVEL__MICROSOFT=Warning
LOGGING__LOGLEVEL__MICROSOFT.ASPNETCORE.DATAPROTECTION=Error
It looks a bit strange with dots in the variable names, but it works.