ASP.NET Core/.NET Core Console app logging in Docker container ASP.NET Core/.NET Core Console app logging in Docker container docker docker

ASP.NET Core/.NET Core Console app logging in Docker container


Adding the following to appsettings.json

  "Logging": {    "LogLevel": {      "Default": "Information",      "System": "Information",      "Microsoft": "Information"    },    "Console": {      "IncludeScopes": true    }  }

be sure your project is configured to copy your appsettings, inside of YourProject.csproj ensure

  <ItemGroup>    <Content Include="appsettings.json">      <CopyToOutputDirectory>Always</CopyToOutputDirectory>    </Content>  </ItemGroup>

I then added the config to the logging service.

            services.AddLogging(builder =>                builder                    .AddDebug()                    .AddConsole()                    .AddConfiguration(configuration.GetSection("Logging"))                    .SetMinimumLevel(LogLevel.Information)            );

hope this helps


It is as I suspected. Visual Studio is the man in the middle that swallows all the log messages. I think it has something to do with yaml overrides in docker-compose command that Visual Studio calls to probably enable all the debugging features.

docker-compose  -f "docker-compose.yml" -f "docker-compose.override.yml" -f "obj\Docker\docker-compose.vs.debug.g.yml" -p dockercompose2788718473649893946 up -d --force-recreate --remove-orphans

It looks like following file obj\Docker\docker-compose.vs.debug.g.yml is responsible for the behaviour I am experiencing. When I run this command without it, everything work as expected.

Thank you all for the brainstorming that led to this answer.