Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7983813
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T11:04:41+00:00 2026-06-04T11:04:41+00:00

I have a chunk of code that frequently needs tracing information output so that

  • 0

I have a chunk of code that frequently needs tracing information output so that clients can help debug the output – it’s very math oriented.

I definitely don’t want the tracing to be enabled in production for performance reasons, but having to comment it in and out frequently is becoming a hassle.

I’ve just setup the code like this…

using System.Diagnostics;

const bool TRACING_ENABLED = false;

//math math math....

Trace.WriteLineIf(TRACING_ENABLED, "Minimum Nitrogen Yield: " + minYieldNitrogen);
Trace.WriteLineIf(TRACING_ENABLED, "Minimum Water Yield: " + minYieldWater);
Trace.WriteLineIf(TRACING_ENABLED, "Minimum Seed Yield: " + minYieldSeed);

//more math math trace math trace math...

My question is… is this the best way to enable and disable tracing for debugging? These sorts of lines are scattered throughout the code, so I was hoping to not have to wrap blocks of if or whatever around them for housekeeping’s sake.

Will the compiler optimize these lines out of the assembly since they are provided a constant of false at build time?

Thanks for your insight!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T11:04:43+00:00Added an answer on June 4, 2026 at 11:04 am

    I would use the ConditionalAttribute and a compiler flag to handle this instead.

    This has the advantage of completely removing the methods from your production code – so the conditional check doesn’t even occur.

    Doing this, you could make your own method, such as:

    [Conditional("TRACE")]
    public WriteTraceLine(string message)
    {
         Trace.WriteLine(message);
    }
    

    And then have a TRACE flag in your debug/non-production build settings. This will cause the method to only exist in the compiled source (including the calls) when that flag is defined.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a very simple chunk of code that is designed to simulate keyboard
I have a chunk of javascript that users can copy and paste to put
I have a rather large chunk of code that breaks sometimes, as far as
I have a chunk of code that defines div s and some of the
All, I have a chunk of code that runs over a lot of records
I have written a chunk of code that is aimed at reordering pages. <form
I have a fairly large chunk of code that produces/returns an arraylist of search
I have a chunk of code that I'm using to get the UNC path
I have a chunk of code that I'm using to read MS Office Word
Another migration question, I have another chunk of VB6 code that seems to need

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.