I was following this answer in order to add a appender on runtime. Even though that works for the original poster, I get this exception in line Logger logger = (Logger
In this case make sure that the library you are using for Logger and LoggerFactory should be the same
For example if LoggerFactory is from slf4j then Logger should not be of log4j or java.util. Make sure it is also from slf4j.
Let me know if you still face the issue.