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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T13:34:43+00:00 2026-06-13T13:34:43+00:00

C# does not support C/C++ macros. There are many Q&A related to this in

  • 0

C# does not support C/C++ macros. There are many Q&A related to this in StackOverflow but I couldn’t find answer to specific question.

Let say I am using code like one suggested at http://logging.apache.org/log4net/release/faq.html:

if(log.IsDebugEnabled) 
{
    log.Debug("Entry number: " + i + " is " + entry[i]);
}

This way to enable/disable logging has obvious drawbacks. In C++ I would use a macro like LOG(expr) to improve code readability and to have better control on ‘if(log.IsDebugEnabled)’ part of code (which is probably repeated thousand times in a project).

How can I achieve LOG(expr) – like result in C#?

Thanks!

  • 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-13T13:34:44+00:00Added an answer on June 13, 2026 at 1:34 pm

    Use new log4net XXXXFormat methods instead. They are implemented this way:

    public virtual void DebugFormat(string format, params object[] args)
    {
        if (this.IsDebugEnabled)
        {
           this.Logger.Log(declaringType, m_levelDebug, String.Format(format, args));
        }
    }
    

    Also you will have power of String.Format instead of simple concatenation of strings

    log.DebugFormat("Entry number: {0} is {1}", i, entry[i]);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

F# does not support implicit conversions. I understand that this is a feature, but
Firefox does not support a long path. But in IE code is run smoothly.
I know that mySQL 5.x does not support INTERSECT, but that seems to be
DOMPDF does not support floats . However I am listing many tables, and they
PHP does not support unsigned ints. Is there a way to convert a string
I know that msbuild does not support VDPROJ files, but it maybe built using
I was told that the iPhone does not support multitasking and multithreading. This did
It seems that nginx does not support chunked requests well. But I'm trying to
Hotmail does not support margin in HTML emails. Is there an alternative?
I realize that PHP does not support unsigned integers, but I'm wondering how to

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.