Where does console output go in an IIS hosted app?

一曲冷凌霜 提交于 2021-02-07 11:40:03

问题


Say I have a WCF app hosted in IIS. And in that app I run this line of code:

 Console.WriteLine("Testing, testing 1 2 3");

Where will that be written to? Or is it ignored and just lost?

Is there someway to capture it when needed?


回答1:


Nowhere. More specifically:

NullStream, which is defined as "A Stream with no backing store.". All the methods do nothing or return nothing. It is an internal class to Stream. The following code is taken from Microsoft's source code.

Basically, when one of the Console write methods is call the first time, a call is made to the Windows API function GetStdHandle for "standard output". If no handle is returned a NullStream is created and used.

quoted from here: https://stackoverflow.com/a/2075892/12744

actually, the same answer goes to on to address the second part of your question too:

To actually redirect Console output, regardless of the project type, use

  Console.SetOut(New System.IO.StreamWriter("C:\ConsoleOutput.txt")),


来源:https://stackoverflow.com/questions/9009726/where-does-console-output-go-in-an-iis-hosted-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!