Reputation: 19583
What is the difference between Debug.Write()
and Trace.Write()
? When should each be used?
Upvotes: 25
Views: 13367
Reputation: 2520
One difference too is, that DEBUG is defined (by default) only in Debug project build configuration and TRACE is defined (again by default) in Debug and Release project build configuration. (At least in VS 2015.)
You can change default behavior for each project in project properties.
Upvotes: 2
Reputation: 18994
In the typical release build configuration, the Debug
class is disabled and does nothing. Trace
, however, can still be used in the release. You would typically use Debug.Write
for stuff you only need when debugging and which is too verbose for production.
Here's a good article on Debug, Trace
etc: http://www.codeproject.com/KB/trace/debugtreatise.aspx
However, I'm more inclined to use logging libraries like log4net which can be reconfigured on the fly. So you can still turn on full logging in production if you're investigating problems with your application.
Upvotes: 22
Reputation: 6002
Debug.Write
is only effective on builds where the DEBUG
flag is defined, while Trace.Write
is only effective when the TRACE
flag is defined.
Upvotes: 13