1

Using .ConfigureAndWatch we have configured log4net to reconfigure its logging level without restarting application processes.

A process start we trace the currently configured log level to our trace file. How can we detect and trace to our trace files the log level changes happening through .ConfigureAndWatch?

Peter Meinl
  • 2,566
  • 25
  • 39

2 Answers2

2

I just (re)discovered that ILoggerRepository has a ConfigurationChanged event. Tracing log level changes from there works fine.

    private static void  repository_ConfigurationChanged(object sender, System.EventArgs e)
{
    var currentTracelLevel = ((log4net.Repository.Hierarchy.Logger)_trace.Logger).EffectiveLevel;
    _trace.InfoFormat("----------------------------- log4net level={0}", currentTracelLevel);
}
Peter Meinl
  • 2,566
  • 25
  • 39
  • Nice catch! Didn't think to look into the existing events, I was fixated on the XmlConfigurator – samy Oct 15 '14 at 22:35
0

You can activate the log4net internal debugging, then you will receive messages from the ConfigureAndWatchHandler class when a change occurs, either on the console or in the trace output (see link for more information)


re your comment: In order to pull back the event into your own code and not rely on the console or trace output I'd recommend creating a custom trace appender that loops back into log4net. This way you can filter out messages you want to bring back into your own logs.

Community
  • 1
  • 1
samy
  • 14,832
  • 2
  • 54
  • 82