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

235
Vistas
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 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