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

  • Home
  • SEARCH
  • 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 6938073
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T12:26:45+00:00 2026-05-27T12:26:45+00:00

I need to add some logging to my app, and it needs to be

  • 0

I need to add some logging to my app, and it needs to be in release mode, and I need to make sure that the logging code isn’t running in production. Therefore I’d like to use a #define and #if to make sure the log statements are removed when I move to production.

Trouble is, I need the logging in multiple files, and it’s a pain to put a #define at the top of every file. Is there a way to have a centralized #define? That way I can remove the single #define rather than a #define from all files(which means I’ll almost assuredly forget one).

  • 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-05-27T12:26:45+00:00Added an answer on May 27, 2026 at 12:26 pm

    On the command line, use the /define switch. In Visual Studio, choose the “Build” tab from the properties page for the project and fill in the “Conditional Compilation Symbols” section.

    Consider also instead of using conditional compilation, to instead make your logging methods conditional methods. That’s a more pleasant-looking alternative. That’s how Debug.Assert works; it is a conditional method, so if the debug preprocessor symbol is not defined, the compiler simply removes all calls to the method before code generation.

    See also my article on the subject:

    http://ericlippert.com/2009/09/10/whats-the-difference-between-conditional-compilation-and-the-conditional-attribute/

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

Sidebar

Related Questions

I'm writing some logging/auditing code that will be running in production (not just when
I need to add some lightweight syntactic sugar to JavaScript source code, and process
I want to add some logging capability to a cf.net application running on WM6
A simple question: I need to add some logging to my program. If two
Logger Hi, I have a Spring MVC webapps that needs some server side logging
I need to add some accordian style expand/collapse handles to a series of parent
After inserting new html to DOM,I need to add some listeners to it. But
I am making a custom control I need to add some default keybindings, microsoft
I have a Publishing Portal site and I need to add some announcements to
I use a jquery validation plugin and I need to add some extra checking,

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.