Where is Console.WriteLine part of the ASP.net development environment?

Is it likely that I will see the output of the Console.WriteLine command after deploying my asp.net web application in IIS? (no more than Visual Studio)

I checked this question:

Where does Console.WriteLine go into ASP.NET?

But the problem is that they all talk about a debugging / development environment whose output window can be used to check the output of these lines.

Is there a way to view the output of these lines without installing additional logging tools (e.g. log4net)?

+4
source share
6 answers

Console.WriteLine (which is redirected to Console.Out.WrlteLine by default) is written to Stream.Null , which means things written by it are lost, as indicated in the question .

To redirect Console.Out to another stream, for example a file, use Console.SetOut , for example, in the global.asax file BeginRequest handler . This will redirect any calls to Console.WriteLine to the output file. Remember to close the stream in the EndRequest handler or in a similar place.

As others have said, Console.WriteLine should usually be avoided in a web application or general purpose libraries for this reason. Consider using a log library such as log4net .

+11
source

Console.Out defaults to the stdout host process thread. On Windows, only executables marked as having the Console type have a stdout stream directed to the console window - for all other executable types (GUI and Service processes), then stdout does not go anywhere.

ASP.NET runs in w3wp.exe , which is a service process without a GUI. As @akton points out, it goes into a zero stream, so everything written will be lost.

If you want to track operations for debugging (more precisely, debugging after opening), use Debug.WriteLine or use a logging library such as log4net .

+3
source

I do not think you can. The responsible developer can write information from his code to help debug, but always Trace.Write or Debug.Write , never Console.Write .

+1
source

The accepted answer is correct. But if you want to nail the coffee table with shoes (the wrong target and the wrong tool), you will need to stop iis and start it interactively from the console, log in to the server using the remote desktop and run inetinfo.exe with the appropriate switches from the command cmd.exe lines. Here is one MSDN page that illustrates the technique for older versions of IIS: http://msdn.microsoft.com/en-us/library/aa291261(v=vs.71).aspx I assume that it still works in principle for newer versions of IIS.

If you do not want to use the library, you can always use System.Diagnostics TraceSource, and then redirect the trace to ConsoleTraceListeners in development ( do not forget to attach the console ), and then to the file or database downloaders on server environments.

+1
source

You can capture the output of Console.WriteLine() compiled C # /. Net application running in IIS using DebugView debugging: https://technet.microsoft.com/en-us/sysinternals/bb896647

+1
source

use MessageBox, it helps to do a lot.
regardless of whether you want to monitor the placement in the message box

0
source

Source: https://habr.com/ru/post/1435667/


All Articles