toosensitive
toosensitive

Reputation: 2375

Where will Debug.WriteLine in C# output to when build release?

I put a lot of Debug.WriteLine in my code for debug purposes. When I am ready to build for release, will these Debug.Write influence the release build, and where do they output to?

Upvotes: 24

Views: 5666

Answers (5)

dodsky
dodsky

Reputation: 524

From MSDN: "The ConditionalAttribute attribute is applied to the methods of Debug. Compilers that support ConditionalAttribute ignore calls to these methods unless "DEBUG" is defined as a conditional compilation symbol. Refer to a compiler's documentation to determine whether ConditionalAttribute is supported and the syntax for defining a conditional compilation symbol."

So if your release configuration does not include DEBUG symbol the Debug.WriteLine calls will be omitted during compilation and there will be no output.

Upvotes: 15

asawyer
asawyer

Reputation: 17808

If you switch them to Trace.WriteLine you can define arbitrary listeners in the app/web.config file.

Upvotes: 8

Paul
Paul

Reputation: 5406

Debug.Writeline is not compiled into release code.

Upvotes: 6

Jim Schubert
Jim Schubert

Reputation: 20357

Debug.WriteLine is annotated with the Conditional attribute. (see MSDN)

The ConditionalAttribute tells the compiler not to generate that code unless the DEBUG flag is supplied.

Upvotes: 19

evanmcdonnal
evanmcdonnal

Reputation: 48096

I believe it will be compiled out.

Upvotes: 1

Related Questions