tush1r
tush1r

Reputation: 19583

What is the difference between Debug.Write and Trace.Write?

What is the difference between Debug.Write() and Trace.Write()? When should each be used?

Upvotes: 25

Views: 13367

Answers (3)

honzakuzel1989
honzakuzel1989

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.

Debug: enter image description here

Release: enter image description here

Upvotes: 2

Igor Brejc
Igor Brejc

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

Tormod Fjeldskår
Tormod Fjeldskår

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

Related Questions