Kevin Hakanson Kevin Hakanson - 2 months ago 14x
ASP.NET (C#) Question

Where does Console.WriteLine go in ASP.NET?

In a J2EE application (like one running in WebSphere), when I use

, my text goes to standard out, which is mapped to a file by the WebSphere admin console.

In an ASP.NET application (like one running in IIS), where does the output of
go? The IIS process must have a stdin, stdout and stderr; but is stdout mapped to the Windows version of /dev/null or am I missing a key concept here?

I'm not asking if I should log there (I use log4net), but where does the output go? My best info came from this discussion where they say
can change the
, 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.


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.

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.

Also, apart from calling SetOut, there is no way to configure the default.