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

810
Vistas
Is there a way in Serilog to filter Messages that starts with certain keyword?

I have a project with following Serilog configuration which works perfectly fine in using filter to exclude logs whose SourceContext starts with "Microsoft.".

"Serilog": {
    "WriteTo": [           
        {
            "Name": "File",
            "Args": {                    
                "path": "C:\\FE\\Logs\\Gateway\\LOG-.txt",
                "outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss.fffffff}  | {Level:u3} {Message}"                   
            }
        }
    ],
    "Filter": [
        {
            "Name": "ByExcluding",
            "Args": {
                "expression": "StartsWith(SourceContext, 'Microsoft.')"
            }
        }
    ],
    "Enrich": [
        "FromLogContext",
        "WithMachineName"            
    ]
}

I am looking for something that would filter the logs by certain keyword on message. So instead of using SourceContext, I need to filter logs whose actual Message starts from keyword "AUDIT:".

I tried to filter by using something like following but it did not work.

    "Filter": [
        {
            "Name": "ByIncludingOnly",
            "Args": {
                "expression": "StartsWith(Message, 'AUDIT:')"
            }
        }
    ]

Any idea if we can even achieve something like this?

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

I found out what the issue was. In case for filtering via Message, we need to put @ infront of Message unlike SourceContext. So the following filter worked:

     "Filter": [
            {
              "Name": "ByExcluding",
              "Args": {
                "expression": "StartsWith(@Message, 'AUDIT::')"
              }
            }
          ]
over 4 years ago · Santiago Trujillo Denunciar
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