What is the difference between Console.WriteLine()
and Trace.WriteLine()
?
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.
WriteLine(String) Writes a message to the trace listeners in the Listeners collection. WriteLine(Object, String) Writes a category name and the value of the object's ToString() method to the trace listeners in the Listeners collection.
WriteLine(Object) Writes the text representation of the specified object, followed by the current line terminator, to the standard output stream. WriteLine(String, Object, Object, Object, Object)
Write. Line() is a function: Writes the current line terminator to the standard output stream. Console. WriteLine() is a method: Writes data, followed by the current line terminator, to the standard output stream.
Look at these from the "Debugging" perspective.
Console.WriteLine()
Debug.WriteLine()
, which prints my debug information on Visual Studio output window.Trace.WriteLine()
in release mode. In debug mode we can see outputs from both Debug.WriteLine()
and Trace.WriteLine()
.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:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With