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

355
Visualizações
Read NLog configuration from database instead of config file

is it possible to read NLog .NET configurations from database? My need is to rapidally change the severity of targets rule's, so I'm wondering if there is a way to do that. For example, if in a configuration file I have this:

<rules>
  <logger name="*" minlevel="Warning" writeTo="LogToDB" />
  <logger name="*" minlevel="Info" writeTo="LogToConsole" />
</rules>

I wanna be able to rapidally change minlevel="value" values (i.e. from database configuration table), without deploy the application configuration file.

Thanks a lots.

over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

You can reconfigure logging at runtime using APIs provided by NLog. Use below function to reconfigure logging -

public void ReconfigureLoggingLevel()
{
    foreach (var rule in NLog.LogManager.Configuration.LoggingRules)
    {
        var logLevel = GetLogLevelFromDatabase(); // your logic to fetch log level
        rule.EnableLoggingForLevel(NLog.LogLevel.FromString(logLevel));
    }
    NLog.LogManager.ReconfigExistingLoggers();
}
over 4 years ago · Santiago Trujillo Relatório

0

You can also do this:

<variable name="MinLevelDB" value="Warning" />
<variable name="MinLevelConsole" value="Info" />

<rules>
  <logger name="*" minlevel="${var:MinLevelDB}" writeTo="LogToDB" />
  <logger name="*" minlevel="${var:MinLevelConsole}" writeTo="LogToConsole" />
</rules>

And then you can do this:

LogManager.Configuration.Variables["MinLevelDB"] = "Debug";
LogManager.ReconfigExistingLoggers();

See also: https://github.com/NLog/NLog/wiki/Filtering-log-messages#semi-dynamic-routing-rules

over 4 years ago · Santiago Trujillo Relatório
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