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

230
Visualizações
Serilog custom exception message

My current task : I need to remove StackTrace from {Exception} object in OutputTemplate

"WriteTo": [
      {
        "Name": "Console",
        "Args": {
          "outputTemplate": "[{Timestamp:yyyy:MM:dd hh:mm:ss} {CorrelationId} {Level:u3}] {Message:lj}{NewLine}{Exception}"
        }
      }]

Exception object contains Message AND StackTrace. I need to remove StackTrace. Is it possible?

I have tried custom property inside custom Enricher:

public class ExceptionEnricherTest : ILogEventEnricher
     {
          public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
          {
              if (logEvent.Exception == null)
              {
                  return;
              }
    
         var logEventProperty = propertyFactory.CreateProperty("ExceptionWithoutStackTrace", logEvent.Exception.Message);
    
            logEvent.AddPropertyIfAbsent(logEventProperty);
          }
     }
public static class LoggingExtensions
    {
        public static LoggerConfiguration WithExceptionEnricher(
            this LoggerEnrichmentConfiguration enrich)
        {
            if (enrich == null)
                throw new ArgumentNullException(nameof(enrich));

            return enrich.With<ExceptionEnricherTest>();
        }
    }

Appsettings in this case :

"Enrich": [ "FromLogContext", "WithCorrelationId", "WithExceptionEnricher" ]

"WriteTo": [
      {
        "Name": "Console",
        "Args": {
          "outputTemplate": "[{Timestamp:yyyy:MM:dd hh:mm:ss} {CorrelationId} {ClientIp} {Level:u3}] {Message:lj}{NewLine}{ExceptionWithoutStackTrace}"
        }
      }]

But I don`t see my custom property.

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