Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

227
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda