6

I''m trying to get log output (Console.WriteLine(..)) in my Docker logs, but I'm getting zero avail.

I've tried:

Console.WriteLine(..)

Trace.WriteLine(..)

Flushing the console, flushing the trace.

I can see these outputs in a VS output window when I'm debugging, so they go somoewhere.

I'm on windows Container, using microsoft/aspnet:4.7.1-windowsservercore-1709 and net4.7

These are the logs I get on container start

 docker logs -f exportapi
ERROR ( message:Cannot find requested collection element. )
Applied configuration changes to section "system.applicationHost/applicationPools" for "MACHINE/WEBROOT/APPHOST" at configuration commit path "MACHINE/WEBROOT/APPHOST"
Stuart.Sklinar
  • 3,683
  • 4
  • 35
  • 89
  • would you confirm that when you ```-it``` attach to the container you see what you expect? ie. clarify whether this is a question about ```docker logs``` or more about your application's (console application template?) logging preferences as they're ultimately set inside the container – nik.shornikov Feb 14 '18 at 16:56
  • 1
    I'm not sure what you're asking me to do - `-it` to what? Don't I need to run a shell of some sort? I'd like my console.WriteLine to show up in the `STDOUT` - Which it should? – Stuart.Sklinar Feb 14 '18 at 17:01
  • I think I've found the issue - the entry point ISN'T my application - but ServiceMonitor.exe (IIS Container) - so it's swallowing all the output - i'll post a solution when I find one. – Stuart.Sklinar Feb 14 '18 at 17:44
  • you answered my question with the section you added that command and output; I was asking whether you see what you expect when doing `docker run -it` – nik.shornikov Feb 14 '18 at 18:34
  • I guess I would - It turns out it's an IIS thing... As the image is has an entry point of ServiceMonitor, it swallows all my console logging.. – Stuart.Sklinar Feb 15 '18 at 09:55
  • @Stuart.Sklinar - Were you able to find a solution to see Console STOUT Logs – Unbreakable Jul 24 '19 at 17:27
  • @Unbreakable I can't remember sorry – Stuart.Sklinar Jul 26 '19 at 13:07

1 Answers1

2

You have many good lateral options, like self-contained/server-contained executables (eg. Dotnet Core using microsoft/dotnet:runtime would proxy Console.WriteLine by default off the dotnet new web scaffold). Zero-configuration STDOUT logging has never been a common approach on IIS, but these modern options adopt it as best practice (logging should be a transparent backing service).

If you want or need a chain of three programs/assemblies to get your web service up (ServiceMonitor, W3SVC, and finally your assembly), then you need something like this: https://blog.sixeyed.com/relay-iis-log-entries-to-read-them-in-docker/

Overriding the entrypoint to tail more logs than the image does by default is unfortunately a common hack (not just in Microsoft land). So, in your case, I believe you need at least a trace listener config to emit Trace.WriteLine, and then the above approach to emit it: https://learn.microsoft.com/en-us/dotnet/framework/debug-trace-profile/how-to-create-and-initialize-trace-listeners

nik.shornikov
  • 1,869
  • 1
  • 17
  • 21
  • 1
    Core isn't on our road map right now, but would solve my issues - I think the issue is because ServiceMonitor swallows everything. – Stuart.Sklinar Feb 15 '18 at 09:55
  • @Stuart.Sklinar it may be an option for you to extract out your business logic and have multiple driver projects (this is a common pattern), if that makes sense; one of them could be self-hosted, whether or not you use Core (https://learn.microsoft.com/en-us/aspnet/web-api/overview/hosting-aspnet-web-api/use-owin-to-self-host-web-api) – nik.shornikov Feb 15 '18 at 16:36
  • I'd totally agree, but that's going down Shaving Yak's for what I needed. – Stuart.Sklinar Feb 16 '18 at 12:58