Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

236
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda