Can’t see logs from VS Code with ASP.NET (Core) using Docker Logs, docker, serilog, vscode-debugger

I’ve created a .NET 5 API project (shortname = webapi) from the dotnet CLI, opened the project in VS Code, added the "required assets to build/debug" (.vscode launch and tasks.json files), and then added Docker support using the command-palette "Docker: Add Docker Files to Project" item — defaults were used with every step. I’ve made no other initial changes (and am using the https flavor of the project).

When I debug the project, I can see the first few log entries (nothing past initial startup) in the Debug Console, but not from the Docker Logs — either from Docker Desktop or the docker logs CLI command. The project runs fine and the Swagger UI works and the API behaves fine. But I can’t see any docker logs.

I’ve run this on two Windows machines and a Mac with the same behavior.

I’ve also tried adding Serilog and writing to the console, and this fixes the "no logs past startup" issue – meaning that I can see all of the appropriate logs in the Debug Console within VS Code, but I still cannot see any logs in Docker Desktop or the CLI.

NOTE: I can see the container itself, and "stats" and other info from the docker tooling — just not the logs.

Am I just missing a setting somewhere or a docker option that should be set within VS Code?

When I do the same things from Visual Studio the docker logs show up fine.

Specific steps:

  • dotnet new webapi -o <someprojectname>
  • open VS Code in the folder for the new project
  • Add the "required assets to build and debug"
  • Invoke the Docker: Add Docker Files to Workspace command (Linux containers) with all defaults
  • Launch the Docker profile

Problem: Startup logs show up in Debug Console, but no more after that, AND logs don’t show up in Docker tooling at all. Adding Serilog (with Console Sink) fixes the "startup only logs" issue, but the logs STILL don’t show up in Docker tooling.

Source: Docker Questions