Console.WriteLine does not show up in Output window
If you intend to use this output in production, then use the Trace class members. This makes the code portable, you can wire up different types of listeners and output to the console window, debug window, log file, or whatever else you like.
If this is just some temporary debugging code that you're using to verify that certain code is being executed or has the correct values, then use the Debug class as Zach suggests.
If you absolutely must use the console, then you can attach a console in the program's Main
method.
Console.WriteLine does not output to Output Window in VS 2017
VS 2017 ( Community ) does not have "Hosting Process" as in VS 2015.
In VS 2015 the "Hosting Process" can be enabled in the Debug panel of the Project Properties.
With the "Hosting Process" is possible to output to Output Window ( when launching a Release config with Start Debugging ) using Console.WriteLine().
In VS 2017 there is no such enabler and so the Console.WriteLine() does not output to Output Window anymore.
Discovered that (System.Diagnostics.)Trace.WriteLine(Format(...)) outputs to Output Window in Release configs and can replace (System.)Console.WriteLine.
Why doesn't Console.Writeline, Console.Write work in Visual Studio Express?
Console.WriteLine
writes your output to the console window opened by your application (think black window with white text that appears when you open the Command Prompt.) Try System.Diagnostics.Debug.WriteLine
instead.
Console writeline does not work
The Console.WriteLine
isn't for IDE output window. It writes to console. So, you could use Debug.WriteLine()
which is available in System.Diagnostics
Debug.WriteLine shows up only in Output window and not Console window
Has been explained in the Microsoft Docs in the TraceListeners collection topic
You can use TextWriterTraceListener and specify the System.Console.Out as the stream where you want to write (or any other suitable stream instance)
TextWriterTraceListener myWriter = new TextWriterTraceListener(System.Console.Out);
Debug.Listeners.Add(myWriter);
or just use ConsoleTraceListener.
ConsoleTraceListener trc = new ConsoleTraceListener();
Debug.Listeners.Add(trc);
Another option is to use a pragma directive to overcome the NET Core problem
public static void DebugWriteConsole(string s)
{
#if DEBUG
Console.WriteLine(DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss | ") + s);
#endif
Debug.WriteLine(DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss | ") + s);
if (Log.logger != null)
{
Log.Info(s);
}
}
Related Topics
Moq - Verify Exception Was Thrown
Model Id Property Null in ASP.NET MVC C#
How to Get a Specific Column Value from a Datatable
How to Pass Jquery Variable Value to C# MVC
How to Iterate Though Each Child Node in an Xml File
Response to Preflight Request Doesn't Pass Access Control Check (Angular2)
A Better Way to Use Automapper to Flatten Nested Objects
Accessing a Shared File (Unc) from a Remote, Non-Trusted Domain With Credentials
Json.Net: Deserilization With Double Quotes
Reading Only Specific Columns from a CSV File Out of Many
Algorithm to Detect Overlapping Periods
How to Send a File Document to the Printer and Have It Print
How to Add a Run Button and Compile Button on the Toolbar in Visual Studio
How to Implement Async Task to Fetch Data from Database Using Async and Await
How to Delete a Read-Only File
Getting All Attributes from an Iwebelement With Selenium Webdriver
The Incoming Request Has Too Many Parameters. the Server Supports a Maximum of 2100 Parameters