The following works for me. Is this roughly what you are after?
public static void TestAddingAppender() { log4net.ILog log = log4net.LogManager.GetLogger("MyTestLogger"); log.Info("Not going to log"); ConfigureFileAppender("log.txt"); log.Info("But this is"); } public static void ConfigureFileAppender(string fileName) { log4net.Repository.Hierarchy.Hierarchy h = (log4net.Repository.Hierarchy.Hierarchy)log4net.LogManager.GetLoggerRepo sitory(); log4net.Appender.FileAppender appender = new log4net.Appender.FileAppender(); appender.File = fileName; appender.AppendToFile = true; log4net.Layout.PatternLayout layout = new log4net.Layout.PatternLayout(); layout.ConversionPattern = "%d [%t] %-5p %c [%x] - %m%n"; layout.ActivateOptions(); appender.Layout = layout; appender.ActivateOptions(); h.Root.AddAppender(appender); h.Configured = true; } > -----Original Message----- > From: Chastain, Roy [mailto:[EMAIL PROTECTED] > Sent: 17 November 2004 19:20 > To: 'log4net-user@logging.apache.org' > Subject: How to dynamically setup logging > > I have an application that may or may not want to log using > the RollingFileAppender. I have many places that call > GetLogger. It appears that if a call to GetLogger is done > before the appended is added to the collection > (Hierarchy->Root->AddAppender(the_new_appender) that the > logger that is returned from the GetLogger call does not log > to that appender. > > I guess that the above is reasonable operation, but how does > one do this all this totally dynamically while the program is running. > > Problem is > My code is in a DLL and the application program calls me to > initialize and/or terminate logging. It wants to pass me a > file name to log to and does not pass me that name until it > wants logging enabled. I don't see a way to initialize the > appender with no file name and if I don't initialize the > appender prior to calling GetLogger the logging does not work. > > Have a missed a basic premise of this product, or is this > indeed a catch 22. > > Thanks > ----------------------------------------------------------------- > Roy Chastain > KMSystems, Inc. > 3225 Shallowford Road > Suite 1000 > Marietta, GA 30062 > 770 635-6352 - Voice > 770 635-6351 - FAX > http://www.kmsys.com > >