控制台输出在IIS托管应用程序中的哪里? [英] Where does console output go in an IIS hosted app?
问题描述
说我有一个WCF应用程序托管在IIS中.然后在该应用程序中运行以下代码行:
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?
推荐答案
无处.更具体地说:
NullStream
,它被定义为没有后备存储的流".所有方法都不执行或不执行任何操作.这是一个内部类到Stream
.以下代码摘自Microsoft的源代码.
NullStream
, which is defined as "A Stream with no backing store.". All the methods do nothing or return nothing. It is an internal class toStream
. The following code is taken from Microsoft's source code.
基本上,当 Console
写入方法之一被调用时,第一个时,将对Windows API函数 GetStdHandle
进行调用标准输出".如果没有返回句柄,则会创建一个 NullStream
并用过.
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.
从这里引用: https://stackoverflow.com/a/2075892/12744
实际上,同样的答案也可以解决您问题的第二部分:
actually, the same answer goes to on to address the second part of your question too:
要实际重定向Console输出,无论项目类型如何,请使用
To actually redirect Console output, regardless of the project type, use
Console.SetOut(New System.IO.StreamWriter("C:\ConsoleOutput.txt")),
这篇关于控制台输出在IIS托管应用程序中的哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!