You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4net-user@logging.apache.org by da...@o-i.com on 2009/02/17 22:49:03 UTC

Programmatically change file path for appender with additivity = false

Hi,
I'm trying to programmatically change the log file destination for a logger using the following code
found on this list:

public static void UpdateFileAppenderPaths(string theNewPath) {
  log4net.Repository.Hierarchy.Hierarchy h =
  (log4net.Repository.Hierarchy.Hierarchy) log4net.LogManager.GetRepository();
  foreach (IAppender a in h.Root.Appenders) {

    if (a is FileAppender) {
      FileAppender fa = (FileAppender) a;
      fa.File = theNewPath;
      fa.ActivateOptions();
    }
  }
}

 However, I've found that my logger doesn't show up in the Hierarchy returned.  My best guess is that it
is because it has additivity = false and is therefore outside of the h.Root structure.
Can someone confirm this guess?
If I'm correct, can you also tell me how to gain access to the appender to change the file path?

Thanks,

Dan