Difference between Console.writeline() /trace.writ

2020-07-13 12:49发布

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

标签: console trace
2条回答
ら.Afraid
2楼-- · 2020-07-13 13:30

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:

查看更多
聊天终结者
3楼-- · 2020-07-13 13:51

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

查看更多
登录 后发表回答