Hi Danish, On Tue, 1 Aug 2023 at 20:10, Danish Arif <danishmari...@gmail.com> wrote: > My use case is that my application uses the above mentioned method to get > logger and log. Appender and Logger have been set in log4j2.xml file. We > stop the Logger by getting all core appenders , removing them , then > stopping them and then using the LogManager.shutdown() method.
There is no need for that, because: 1. LogManager.shutdown() stops all appenders, 2. Usually the `log4j2.shutdownHookEnabled` property is set to true, so LogManager.shutdown() is called by a shutdown hook. > The issue or anomaly arises when an update batch script starts the new > instance of the same application and the old instance takes some time to > exit, resulting in new instance getting the same logger using > LogManager.getLogger("AppName"); and writing in the same log file. > > Once the 1st/old instance exists after a few seconds, it closes all the > logging and nothing on the file gets written even when the 2nd/new instance > is still up and running. If these instances are in different JVM's, this is strange: can you add the configuration of your file appender? If you are using a `RollingFileAppender`, it can rotate your file and delete the old ones. If these instances are in the same JVM, you might be up to something: apparently `stop()` is not idempotent and if you call it enough times, you can effectively stop appenders in other logger contexts. Piotr --------------------------------------------------------------------- To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org For additional commands, e-mail: log4j-user-h...@logging.apache.org