Assuming you are using log4net out of the box, you can dig your way down and hide the application this way:
public void FlushBuffers() { ILog log = LogManager.GetLogger("whatever"); var logger = log.Logger as Logger; if (logger != null) { foreach (IAppender appender in logger.Appenders) { var buffered = appender as BufferingAppenderSkeleton; if (buffered != null) { buffered.Flush(); } } } }
Change I wrote above on the assumption that you want to drop applications for a specific ILog (probably a bad assumption now when I re-read the question), but like Stefan in the following comment, you can simplify the code a bit if you want to reset all consoles throughout the repository in the following way:
public void FlushBuffers() { ILoggerRepository rep = LogManager.GetRepository(); foreach (IAppender appender in rep.GetAppenders()) { var buffered = appender as BufferingAppenderSkeleton; if (buffered != null) { buffered.Flush(); } } }
Alconja Jan 12 2018-10-12T00: 00-01
source share