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

147
Vistas
Multi-threaded logging in log4net & C#

We have a multi-threaded task execution service which is frequently executing tasks in parallel. As part of our log messages we want to have the task name as well as an execution id (ContextKey). Currently trying to set context key in the task constructor:

public AsyncTaskBase(ILogger logger, IContextKeyLocator locator)
{
    _Logger = logger;
    _ContextKeyLocator = locator;
    contextKey = _ContextKeyLocator.GenerateAndSetContextKey();
    log4net.ThreadContext.Properties["ContextKey"] = contextKey;
}

From there we leave it up to the log4net appender pattern to log the context key

<conversionPattern value="%date [%thread] %-5level [%property{ContextKey}] - %message" />

And what we see in the logs are series of log messages with the same thread/contextKey values that were most definitely not from the same task.

So my question is how do I handle this kind of situation? We have properties we'd like to have in the log message that are contextual only to the current execution, but it also needs to be thread safe. Any help, guidance, direction, would be great. Thank you in advance!

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