tags:

views:

4688

answers:

8

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.

In an ASP.NET application (like one running in IIS), where does the output of Console.WriteLine() 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 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.

+1  A: 

It would actually go to the STDOUT of the ASP.NET Worker process.

Where that is pointed to, I'm not sure.

FlySwat
That's the question - where does STDOUT go?
Kevin Hakanson
A: 

in an ASP.NET application, i think it goes to the Output or Console window which is visible during debugging.

Leon Tayson
+1  A: 

Unless you are in a strict console application, I wouldn't use it, beause you can't really see it. I would use Trace.WriteLine() for debuggin type information that can be turned on and off in production.

Charles Graham
Yep, here's a good place to start: http://msdn.microsoft.com/en-us/library/x5952w0c.aspx
Zhaph - Ben Duguid
+3  A: 

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.

Craig Tyler
+18  A: 

If you use System.Diagnostics.Debug.WriteLine(...) instead of Console.WriteLine(), then you can see the results in the Output window of Visual Studio.

Greg Bernhardt
The question is where does the Console.Writeline() go.
Kevin Hakanson
But that's still a very useful contribution. It helped me
Ryan
A: 

System.Diagnostics.Debug.Writeline or System.Diagnostics.Trace.Writeline

don't work neither and display nothing in the output window :-/

How to attach the DefaultListener to this window ???

MiniScalope
+12  A: 

If you look at the Console class in 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 IO taking place with the null device.

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

Ruben
A: 

I've found this question by trying to change the Log output of the DataContext to the output window. So to anyone else trying to do the same, what I've done was create this:

class DebugTextWriter : System.IO.TextWriter {
   public override void Write(char[] buffer, int index, int count) {
       System.Diagnostics.Debug.Write(new String(buffer, index, count));
   }

   public override void Write(string value) {
       System.Diagnostics.Debug.Write(value);
   }

   public override Encoding Encoding {
       get { return System.Text.Encoding.Default; }
   }
}

Annd after that: dc.Log = new DebugTextWriter() and I can see all the queries in the output window (dc is the DataContext).

Have a look at this for more info: http://damieng.com/blog/2008/07/30/linq-to-sql-log-to-debug-window-file-memory-or-multiple-writers

Artur Carvalho