After weeks of trying I now finally found a solution. The key event was the discovery, that also the PropertyConfigurator has a class for ErrorHandler, although Geki wrote, that there is no possibility to configure a ErrorHandler with the PropertyConfigurator. So I went on trying.
Now I could simply combine the basic declaration in the log4j.properties with the linking of Logger, Appender and ErrorHandler in JavaCode.
So following stands in my Properties:
log4j.appender.ServerAppender=org.apache.log4j.FileAppender
log4j.appender.ServerAppender.layout=org.apache.log4j.PatternLayout
log4j.appender.ServerAppender.layout.ConversionPattern=%d{dd MMM yyyy HH:mm:ss,SSS} [%t] %-5p %F - %m%n
log4j.appender.ServerAppender.file=logs/ServerLog.txt
log4j.appender.ServerAppender.threshold=DEBUG
log4j.logger.com.foo.server=TRACE, ServerAppender
log4j.appender.ServerAppender.errorhandler=org.apache.log4j.varia.FallbackErrorHandler
log4j.appender.ServerAppender.errorhandler.logger-ref=com.foo.server
log4j.appender.ServerAppender.errorhandler.appender-ref=FallbackServerAppender
log4j.appender.FallbackServerAppender=org.apache.log4j.FileAppender
log4j.appender.FallbackServerAppender.layout=org.apache.log4j.PatternLayout
log4j.appender.FallbackServerAppender.layout.ConversionPattern=%d{dd MMM yyyy HH:mm:ss,SSS} [%t] %-5p %F - %m%n
log4j.appender.FallbackServerAppender.file=C:/Temp/Test/fallbackServerLog.txt
log4j.logger.com.foo.error=DEBUG,FallbackServerAppender
While com.foo.server is a part of my package hierarchy, com.foo.error is only a placeholder, so I can call it within Java-Code. That will look like this.
PropertyConfigurator.configure(LOG4JCONFIG);
FallbackErrorHandler fbeh=(FallbackErrorHandler)LogManager.getLogger("com.foo.server").getAppender("ServerAppender").getErrorHandler();
fbeh.setLogger(LogManager.getLogger("com.foo.server"));
fbeh.setAppender(LogManager.getLogger("com.foo.server").getAppender("ServerAppender"));
fbeh.setBackupAppender(LogManager.getLogger("com.foo.error").getAppender("FallbackServerAppender"));
A known problem, the fallbackErrorHandler doesn´t reset when the Appender is on again, could be solved by restarting the configure()-method in or after situations, where normally the normal Appender can´t log.
Hope it could help somebody :)