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 6093019
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T12:30:43+00:00 2026-05-23T12:30:43+00:00

I need to Log messages only when application is running in debug mode. I

  • 0

I need to Log messages only when application is running in debug mode. I have found 2 ways:

First: Need to write 3 lines everywhere when logging is needed. But, Logger statement is disabled at compile time only which is exactly I need. Logger.Log will not be executed at all.

#if DEV_ENV
        Logger.Log("Application started !"); // This line is grayed. Perfect !
#endif

public static void Log(string message)
{
    Debug.WriteLine(message);
}

Second: Very neat. Only one line of code wherever logging is required. Not sure, whether Logger.Log statement is executed or not. If function call is removed at compile time only (same as first approach. But, now sure as line of code is not greyed out), I want to go with this.

Logger.Log("Application started !"); // This line is not grayed out. But, function is not called. So, confused whether its removed at compile time.

[Conditional("DEV_ENV")]
public static void Log(string message)
{
    Debug.WriteLine(message);
}

I am concerned about the performance differences.

  • 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-23T12:30:44+00:00Added an answer on May 23, 2026 at 12:30 pm

    From the MSDN page for the ConditionalAttribute:

    Applying ConditionalAttribute to a
    method indicates to compilers that a
    call to the method should not be
    compiled
    into Microsoft intermediate
    language (MSIL) unless the conditional
    compilation symbol that is associated
    with ConditionalAttribute is defined.

    So, as it says, the method call is removed at compile time, same as the #if.

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

Sidebar

Related Questions

i have a log file which contains hundreds/thousands of seperate XML messages and need
I have a WCF client for which I need to log messages. I need
This is my problem: I need to store a lot of log messages and
I need to log information about how much RAM the user has. My first
I have created a webservice in .net 2.0, C#. I need to log some
I would like to log errors/informational and warning messages from within my web application
I have an Apache Derby database running (in networked mode) inside a java swing
I need a system to log certain e-mail messages so that they can be
Currently, I have a log file of messages in one table in a MySQL
Yesterday i implement Log4Net in my application. To use it i need to write

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.