Difference between Console.writeline() /trace.writeline()

吃可爱长大的小学妹 提交于 2019-12-22 10:59:53

问题


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



来源:https://stackoverflow.com/questions/42548412/difference-between-console-writeline-trace-writeline

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!