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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T17:03:40+00:00 2026-05-10T17:03:40+00:00

I’m a big fan of log4net , but recently, some (in my department) have

  • 0

I’m a big fan of log4net, but recently, some (in my department) have questioned its inclusion in our projects because of the seemingly heaviness of each logging method. I would argue that there are better techniques than others, but that’s another question.

I’m curious to know, what is the typical impact of a log4net DebugFormat-type call on your applications. I’m going to leave out variables like number of log statements per lines of code, etc, because I’m just looking for anything that you’ve seen in the real world.

And, I am aware of the simple technique of adding a guard clause to long evaluation statements eg:

if (log.IsDebug) {   log.DebugFormat(...); } 

So, let’s exclude that from consideration for now.

  • 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. 2026-05-10T17:03:40+00:00Added an answer on May 10, 2026 at 5:03 pm

    I am not familiar with log4net, or log.DebugFormat(…).

    But the cost of logging is really in two areas.

    The first is the logging call, and the second is the actual persisting of the log information.

    The guards help reduce the logging call to a minimum when the logging is not actually necessary. It tends to be very fast, since it’s little more than a method call and a comparison of two scalars.

    However, when you don’t use guards, the cost may well become the price of creating the actual logging arguments.

    For example, in log4j, this was a common idiom:

    log.debug('Runtime error. Order #' + order.getOrderNo() + ' is not posted.'); 

    Here, the cost is the actual evaluation of the string expression making the message. This is because regardless of the logging level, that expression, and the resulting string are created. Imagine if instead you had something like:

    log.debug('Something wrong with this list: ' + longListOfData); 

    That could create a large and expensive string variable that, if the log level wasn’t set for DEBUG, would simply be wasted.

    The guards:

    if (log.isDebug()) {     log.debug(...); } 

    Eliminate that problem, since the isDebug call is cheap, especially compared to the actual creation of the argument.

    In my code, I have written a wrapper for logging, and I can create logs like this:

    log.debug('Runtime error. Order # {0} is not posted.', order.getOrderNo()); 

    This is a nice compromise. This relies on Java varargs, and my code checks the logging level, and then formats the message appropriately. This is almost as fast as the guards, but much cleaner to write.

    Now, log.DebugFormat may well do a similar thing, that I don’t know.

    On top of this, of course, is the actual cost of logging (to the screen, to a file, to a socket, etc.). But that’s just a cost you need to accept. My best practice for that, when practical, is to route the actual log messages to a queue, which is then reaped and output to the proper channel using a separate thread. This, at least, helps keep the logging out of line with the main computing, but it has expenses and complexity of its own.

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

Sidebar

Ask A Question

Stats

  • Questions 51k
  • Answers 52k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer You can cast ints in Perl: int(5/1.5) = 3; May 11, 2026 at 6:35 am
  • added an answer The rails team and many other rubyists prefer to use… May 11, 2026 at 6:35 am
  • added an answer It's not about binary versus text, it's about whether it's… May 11, 2026 at 6:35 am

Top Members

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

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.