Q:

Attach or detach appender at runtime

I'm using XML configuration for log4net.  I have the following appender-refs:
<root>
  <level value="ALL" />
  <appender-ref ref="ConsoleAppender" />
  <appender-ref ref="OldRollingLogAppender" />
</root>

(I also have these these appenders defined in the XML—their exact implementation shouldn't matter.) 
I'd like to, at runtime, remove OldRollingLogAppender, and create and add a new one called NewRollingLogAppender.  How do I do this?  
A minimal working example would be nice. 

A:

You can do this by getting the root logger and then add and remove the appenders:
Remove:
var root = ((log4net. Repository. Hierarchy. Hierarchy)LogManager. GetRepository()).Root;
root. RemoveAppender(xxx);

Add:
var root = ((log4net. Repository. Hierarchy. Hierarchy)LogManager. GetRepository()).Root;
root. AddAppender(xxx);

You can iterate the list of appenders with root. Appenders
  https://logging.apache.org/log4net/release/sdk/html/AllMembers_T_log4net_Repository_Hierarchy_RootLogger.htm

