Monday, 9 January 2012

Where does Console.WriteLine go in ASP.NET?

If you wonder where you can see the output from a Console.WriteLine() statement in an ASPX page here is the answer - you can't see it anywhere, because it is not outputted anywhere.

The reaseon is:

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.

The alternative to Console.WriteLine is System.Diagnostics.Debug.WriteLine()

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

No comments:

Post a Comment