Can I use Trace.WriteLine in release mode?
And what is the main difference between Trace.Write and Debug.Write?
Both are conditionally-compiled using the [Conditional]
attribute.
If the TRACE
flag is defined in the build, then calls to the Trace
class will result in trace output being written. By default, TRACE
is defined in both debug and release mode. If the flag is not defined, nothing will happen.
If the DEBUG
flag is defined, then calls to the Debug
class result in output being written to the debug stream. By default, DEBUG
is only defined in debug mode.
The other major difference is that with tracing it's easy to customize the trace listeners and decide later on what you want to do with the trace output. It's more flexible than debug output, and generally better suited to logging in a production application.