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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T08:24:32+00:00 2026-05-13T08:24:32+00:00

Extraneous logging can be expensive. Therefore, I could turn off logging or heighten the

  • 0

Extraneous logging can be expensive. Therefore, I could turn off logging or heighten the logging threshold level to reduce logging during production mode (everybody knows that!)

However, what about the routines that are called to supply parameters to the logger statement?

Consider the logger statement.

logger.info(“number of windows=”+wins.size());

where wins.size() is an excruciatingly expensive operation – say, just for illustration of my (mis)understanding the problem.

If info logging is turned off, would wins.size() still be run.

Because when I do debugging, it seems that wins.size() gets stepped over first before log.info(). If so, what are your strategies to prevent expensive functions inside a logger statement from being executed if the logger is turned off?

  • 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-13T08:24:32+00:00Added an answer on May 13, 2026 at 8:24 am

    In C# 3.0 you could use lambdas to only execute a call to logging function when the logging is turned on. This is example using C# Common.Logging:

    Logger.Trace(m=>m("number of windows="+wins.size()));
    

    where Trace is defined like so:

    void Trace(Action<FormatMessageHandler> formatMessageCallback);
    

    and FormatMessageHandler is

    public delegate string FormatMessageHandler(string format, params object[] args);
    

    So what happens is if tracing is turned on the m=>m("number of windows="+wins.size()) lambda gets called. If it’s off, the expensive call to get the window size is never made.

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

Sidebar

Related Questions

When I call next() I have an extraneous [] in @current . How can
I am getting extraneous output in my .tex file that I can not suppress
I have some code in a python string that contains extraneous empty lines. I
Updated to remove extraneous text and ambiguity. The Rules: An employee accrues 8 hours
This is my attempt to cut through extraneous issues raised Why don’t my system
We've got some really strange extraneous DB hits happening in our project. Is there
I have my log file working, but I get extraneous info on each line
Edit: I need to refactor this question, it has too many extraneous components to
I need to login into a certain website before I can attempt a data
With the following table structure (extraneous columns removed) create table [Events] ( ID int

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.