1

I have a separate Log4Net.config file with 2 appenders and 2 loggers, 1 logger for each appender. There is no <Root /> logger.

I am trying to add code to my application that will retrieve the filename for the logger to allow the user to view the log files for each of the appenders from an application menu selection. I have tried the below code but it returns no appenders. What did I miss?

I should also have mentioned that I am using the slf4net.log4net facade

log4net.Repository.ILoggerRepository repo = LogManager.GetRepository();

foreach (log4net.Appender.IAppender appender in repo.GetAppenders())
{
    string x = appender.Name;
}
Cœur
  • 37,241
  • 25
  • 195
  • 267
Tim
  • 1,249
  • 5
  • 28
  • 54
  • Did you call `XmlConfigurator.Configure()` first? This works for me. – matth Jan 17 '14 at 16:45
  • Calling XmlConfigurator.Configure() causes the logger to return an error, "Failed to find the configuration section log4net in the applications .config file. I should also have mentioned that I am using the slf4net.log4net facade. Adding the node to the config didn't help. It still returned the error. – Tim Jan 17 '14 at 19:39
  • Also note that I have [assembly: log4net.Config.XmlConfigurator(Watch=true)] in the AssemblyInfo.cs – Tim Jan 17 '14 at 19:58

1 Answers1

1

I found the answer in this post log4Net config in external file does not work. After adding the ConfigFile name to the assemblyinfo entry it began working

Community
  • 1
  • 1
Tim
  • 1,249
  • 5
  • 28
  • 54