Can I use Trace.WriteLine in release mode?
And what is the main difference between Trace.Write and Debug.Write?
DEBUG:
RELEASE:
As you see the TRACE constant is enabled in both configs by default
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.
The difference is in Release mode.
Debug.Write will not be compiled into the code when the DEBUG symbol is not defined, i.e. compiling in Release mode.
However, Trace.Write will be compiled in both Debug mode and Release mode.