Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

226
Views
ILogger - resource utilisation for redundant log levels

I send and receive huge JSON Payloads to/from Webservices. I log JSON content at Debug level in easy to read format (Prettifier) and response Code at Information level.

_logger.LogInformation($"statusCode={responseMessage.StatusCode}");
_logger.LogDebug(MyJsonPrettifier(await responseMessage.Content.ReadAsStringAsync));

This is really useful during development - I can quickly inspect what's going on. However, due to how these functions are structured - simple string argument - it will always be executed even if I set the log level to different - Warning when Publish Release version.

I read this article where the difference is shown - application without logs performs 40x faster. The problem is really serious. I develop in .NET5 and I also use Serilog. Is there an easy, universal, perhaps established way to approach this problem?

I could easily improve the problem with a logger that takes callbacks as arguments. Therefore it would only execute the callback if the appropriate Log Level is set.

_logger.LogInformation(
   () => $"statusCode={responseMessage.StatusCode}");

_logger.LogDebug(
   () => MyJsonPrettifier(await responseMessage.Content.ReadAsStringAsync)
);
over 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!