Where does Console.WriteLine go in ASP.NET? Where does Console.WriteLine go in ASP.NET? asp.net asp.net

Where does Console.WriteLine go in ASP.NET?


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


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.

Update 2020-11-02: As this answer is still gathering votes in 2020, it should probably be noted that under ASP.NET Core, there usually is a console attached. You can configure the ASP.NET Core IIS Module to redirect all stdout and stderr output to a log file via the stdoutLogEnabled and stdoutLogFile settings:

<system.webServer>  <aspNetCore processPath="dotnet"              arguments=".\MyApp.dll"              hostingModel="inprocess"              stdoutLogEnabled="true"              stdoutLogFile=".\logs\stdout" /><system.webServer>


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