Console.WriteLine在ASP.NET中位于何处?
本文翻译自:Where does Console.WriteLine go in ASP.NET?
In a J2EE application (like one running in WebSphere), when I use System.out.println()
, my text goes to standard out, which is mapped to a file by the WebSphere admin console. 在一个J2EE应用程序中(就像在WebSphere中运行的应用程序一样),当我使用System.out.println()
,我的文本进入标准输出,该标准输出由WebSphere管理控制台映射到文件。
In an ASP.NET application (like one running in IIS), where does the output of Console.WriteLine()
go? 在ASP.NET应用程序(如在IIS中运行的应用程序)中, Console.WriteLine()
的输出在哪里? The IIS process must have a stdin, stdout and stderr; IIS进程必须具有stdin,stdout和stderr。 but is stdout mapped to the Windows version of /dev/null or am I missing a key concept here? 但是stdout映射到Windows版本的/ dev / null还是在这里缺少关键概念?
I'm not asking if I should log there (I use log4net), but where does the output go? 我不是问我是否应该登录那里(我使用log4net),但是输出会去哪里呢? My best info came from this discussion where they say Console.SetOut()
can change the TextWriter
, but it still didn't answer the question on what the initial value of the Console is, or how to set it in config/outside of runtime code. 我最好的信息来自这个讨论 ,他们说Console.SetOut()
可以更改TextWriter
,但是它仍然没有回答关于Console初始值是什么,或者如何在运行时的config / outside中设置它的问题。码。
#1楼
参考:https://stackoom.com/question/ZoK/Console-WriteLine在ASP-NET中位于何处
#2楼
在ASP.NET应用程序中,我认为它会转到在调试过程中可见的“输出”或“控制台”窗口。
#3楼
Unless you are in a strict console application, I wouldn't use it, because you can't really see it. 除非您使用严格的控制台应用程序,否则我不会使用它,因为您看不到它。 I would use Trace.WriteLine() for debugging-type information that can be turned on and off in production. 我将使用Trace.WriteLine()获得可在生产环境中打开和关闭的调试类型信息。
#4楼
There simply is no console listening by default. 默认情况下,根本没有控制台监听。 Running in debug mode there is a console attached, but in a production environment it is as you suspected, the message just doesn't go anywhere because nothing is listening. 在调试模式下运行时,连接了一个控制台,但是在生产环境中,正如您所怀疑的那样,该消息不会随处可见,因为没有人在听。
#5楼
If you look at the Console
class in .NET Reflector , you'll find that if a process doesn't have an associated console, Console.Out
and Console.Error
are backed by Stream.Null
(wrapped inside a TextWriter
), which is a dummy implementation of Stream
that basically ignores all input, and gives no output. 如果查看.NET Reflector中的Console
类,则会发现如果进程没有关联的控制台,则Stream.Null
(包装在TextWriter
)将支持Console.Out
和Console.Error
Stream
的虚拟实现,基本上忽略所有输入,并且不提供任何输出。
So it is conceptually equivalent to /dev/null
, but the implementation is more streamlined: there's no actual I/O taking place with the null device. 因此,它在概念上等效于/dev/null
,但是实现更加简化:空设备没有实际的I / O发生。
Also, apart from calling SetOut
, there is no way to configure the default. 此外,除了调用SetOut
,无法配置默认值。
#6楼
System.Diagnostics.Debug.WriteLine(...);
gets it into the Immediate Window in Visual Studio 2008. 将其放入Visual Studio 2008中的“ 立即窗口” 。
Go to menu Debug -> Windows -> Immediate : 转到菜单调试 -> Windows- > 立即 :