Hello Community!
I have a problem using Apache's Log4j logging functionality.
The configuration file looks as follows:<?xmlversion ="1.0"encoding="UTF-8"?>
%d{yyyy-mm-dd HH:mm:ss.SSS} [%t] %-5level %C.%M(%F:%L) - %msg%n%throwable{full}
As seen, the primary logger shall write the information to a database table. This works fine.
The problem occurs when the logger cannot write to the database.
As I understand the "Failover" logger, it should use the "HDRollingFile" logger in this situation. But after the program has ended, the Log-file is still empty.
With the Configuration status="warn" level, I get the following error: ERROR appender Failover has no parameter that matches element Failovers
But this code is exactly like the code in the Log4j2 documentation.
The result is, the exceptions for the database not being accessible, are printed to the console, but none of my logging information I am generating in my program code.
Does anybody have a clue what is going on here and how to fix it?
Thanks in advance. :)
解决方案I have the exact same problem, and I believe we are not alone. I see very strange behaviour, wherein my integration test, which uses an identical classpath (except the additional testing libs), does NOT throw this error and so failover works. So, my integration tests pass but when I run my code from my main() method, the log4j2 config throws this lame error.
I've tried re-ordering my elements but according to the documentation, the way you have them listed is correct. If I had to guess, there is a race condition in the config manager that tries to initialize the failover appender before it's instantiated. Why this doesn't happen in my integration tests, I don't know. It's a real time sucker to track down and this behaviour is critical to my application.