My application uses several appenders -- a FileAppender
, MemoryAppender
, and AdoNetAppender
. I have a command to reset the log so that a new file gets created on demand. This works great -- I simply call log4net.LogManager.GetRepository().Shutdown()
.
I also log simultaneously to the MemoryAppender
, and I have a timer that pulls events out of the appender and displays them in a log window. When I use the aforementioned reset function, the log window stops displaying messages because no more events are being logged.
For the FileAppender
, I was able to get it to start logging again by calling ActivateOptions
after setting a proper filename. I have called ActivateOptions
on the MemoryAppender
, but that doesn't get it to start logging again. Before calling ActivateOptions
, I have looked at the object to ensure that it is already configured. It actually preserves the configuration from the time I called the reset function, so that seems okay.
I have also searched online, and people have said that you just have to call log4net.Config.DOMConfigurator.Configure
(deprecated -- now it is log4net.Config.XmlConfigurator.Configure`), but that didn't work, either.
Is there another method I can try to shutdown / restart logging, while supporting File, Memory, and Ado appenders?
I think you get what you want by not calling the Shutdown
method. Simply set a new file name on your appender and call ActivateOptions
. This will close the old log file and open the new one...