0

I realize the difference between the two:

"Console.WriteLine writes to the standard output stream, either in debug or release. Debug.WriteLine writes to the trace listeners in the Listeners collection, but only when running in debug. When the application is compiled in the release configuration, the Debug elements will not be compiled into the code."

But which is normally used in a Xamarin app and what are the consequences of using Console.Writeline?

Alan2
  • 23,493
  • 79
  • 256
  • 450
  • This link of a similar question may help clarify: https://stackoverflow.com/questions/35847530/xamarin-forms-debug-writeline-where-does-the-output-go – Zaren Wienclaw Oct 28 '19 at 17:58

2 Answers2

2

Just as you mentioned,

Console.WriteLine writes to the standard output stream, either in debug or release. Debug.WriteLine writes to the trace listeners in the Listeners collection, but only when running in debug. When the application is compiled in the release configuration, the Debug elements will not be compiled into the code.

In short, if you want to show a message to your user in a console application, you could use Console.WriteLine,if your purpose is solely for debugging, it is recommended that you use Debug.WriteLine.

But we know that we shouldn't print all debug information in release mode, so we should use Trace.WriteLine() in release mode. In debug mode we can see outputs from both Debug.WriteLine() and Trace.WriteLine().

For more details, you can check this document: How to trace and debug in Visual C#

From this document,we will find:

You can use the Trace and the Debug classes separately or together in the same application. In a Debug Solution Configuration project, both Trace and Debug output are active. The project generates output from both of these classes to all Listener objects. However, a Release Solution Configuration project only generates output from a Trace class. The Release Solution Configuration project ignores any Debug class method invocations."

The following link should be helpful for you.

Trace logs location, where to view them

https://learn.microsoft.com/en-us/visualstudio/debugger/how-to-set-debug-and-release-configurations?view=vs-2015&redirectedfrom=MSDN

Jessie Zhang -MSFT
  • 9,830
  • 1
  • 7
  • 19
  • so `console` is for developer? `Debug` is for debug mode? and `trace` is for when app is released? –  May 28 '21 at 19:30
0

Console.Writeline is an data debug output just for development, you can use it for check if some function are retrieving the right output, check if output data formating are good and etc.

use this only for development purposes

ps: the most common one is Console.Writeline()

Guilherme Nimer
  • 555
  • 2
  • 14