2

What does Console.WriteLine(exception.Message); do on an ASP.NET website?

In ASP.NET, where is the Console? If I use Console.WriteLine(exception.Message); on an ASP.NET website, does this output the message in a log file stored on the server somewhere?

uSeRnAmEhAhAhAhAhA
  • 2,527
  • 6
  • 39
  • 64

1 Answers1

3

It does nothing, because there is no Console, so there is nowhere to output whatever you are trying to output. It will not be automatically logged anywhere - you must set that up yourself.

--

To expand just slightly

The Console class specifically refers to the console window in a console application (i.e., a non-graphical DOS style executable program).

In ASP.net, your code runs on a web server, and there is no such thing as a console.

If you need to log debug/exception output, look into using Log4net or something similar, or roll your own.

Dmitriy Khaykin
  • 5,238
  • 1
  • 20
  • 32
  • Thank you @David! I will accept when the timer allows me. – uSeRnAmEhAhAhAhAhA Mar 31 '14 at 18:11
  • 1
    +1. Also it is probably possible to allocate and attach console even to server process... Never tried it so no idea if it would actually work (but again there would be no way to see output - purely theoretical exercise :) ) – Alexei Levenkov Mar 31 '14 at 18:15
  • 2
    FYI - in ASP.NET, since there is no console, the `Console` object is backed by `Stream.Null` which essentially means it ignores input. A reasonably good explanation can be found here: http://stackoverflow.com/a/1432088/1630665 – Dave Zych Mar 31 '14 at 18:17