Difference between Console.writeline() /trace.writ

2020-07-13 13:42发布

问题:

What is the difference between Console.WriteLine() and Trace.WriteLine() ?

回答1:

Look at these from the "Debugging" perspective.

  • We started debugging using Console.WriteLine()
  • Later we got to know it might not be good to print debugging data on console always. We might not even have a console. Then we started using Debug.WriteLine(), which prints my debug information on Visual Studio output window.
  • Then we got to 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().
  • Here's a very good reference: Usage of Trace and Debug

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."

Here are some relevant items that you might find useful:

  • Where to look for trace logs ?
  • How to set Debug or Release Configurations ?
  • Understanding build configurations.


回答2:

From MSDN website: Console.WriteLine() writes the specified data, followed by the current line terminator, to the standard output stream. Meanwhile, Trace.WriteLine() writes information about the trace to the trace listeners in the Listeners collection



标签: console trace