Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check whether log4net XmlConfigurator succeeded

Tags:

.net

log4net

How to check whether a call to log4net's XmlConfigurator.Configure succeeded? I want to make a web service call if the logging configuration could not be loaded properly (i.e. file not existent, file not well-formed, etc.)

like image 836
D.R. Avatar asked Feb 25 '15 16:02

D.R.


1 Answers

From the FAQ:

To prevent silent failure of log4net as reported as LOG4NET-342, log4net supports a way to evaluate if it was configured and also to evaluate messages generated on startup since 1.2.11. To check if log4net was started and configured properly one can check the property log4net.Repository.ILoggerRepository.Configured and enumerate the configuration messages as follows:

if(!log4net.LogManager.GetRepository().Configured)
{
  // log4net not configured
  foreach(log4net.Util.LogLog message in log4net.LogManager.GetRepository().ConfigurationMessages.Cast<log4net.Util.LogLog>())
  {
      // evaluate configuration message
  }
}
like image 79
Jeroen Mostert Avatar answered Sep 18 '22 13:09

Jeroen Mostert