@@ -72,31 +72,39 @@ void shouldDetectMultipleBufferingAppendersRegardlessOfName() throws IOException
7272 // may not be there in the first run
7373 }
7474
75- ConfigurationFactory factory = new XmlConfigurationFactory ();
76- ConfigurationSource source = new ConfigurationSource (
77- getClass ().getResourceAsStream ("/log4j2-multiple-buffering.xml" ));
78- Configuration config = factory .getConfiguration (null , source );
79-
8075 LoggerContext ctx = (LoggerContext ) LogManager .getContext (false );
81- ctx .setConfiguration (config );
82- ctx .updateLoggers ();
83-
84- org .apache .logging .log4j .Logger logger = LogManager .getLogger ("test.multiple.appenders" );
85-
86- // When - log messages and flush buffers
87- logger .debug ("Test message 1" );
88- logger .debug ("Test message 2" );
76+ Configuration originalConfig = ctx .getConfiguration ();
8977
90- Log4jLoggingManager manager = new Log4jLoggingManager ();
91- manager .flushBuffer ();
92-
93- // Then - both appenders should have flushed their buffers
94- File logFile = new File ("target/logfile.json" );
95- assertThat (logFile ).exists ();
96- String content = contentOf (logFile );
97- // Each message should appear twice (once from each BufferingAppender)
98- assertThat (content .split ("Test message 1" , -1 )).hasSize (3 ); // 2 occurrences = 3 parts
99- assertThat (content .split ("Test message 2" , -1 )).hasSize (3 ); // 2 occurrences = 3 parts
78+ try {
79+ ConfigurationFactory factory = new XmlConfigurationFactory ();
80+ ConfigurationSource source = new ConfigurationSource (
81+ getClass ().getResourceAsStream ("/log4j2-multiple-buffering.xml" ));
82+ Configuration config = factory .getConfiguration (null , source );
83+
84+ ctx .setConfiguration (config );
85+ ctx .updateLoggers ();
86+
87+ org .apache .logging .log4j .Logger logger = LogManager .getLogger ("test.multiple.appenders" );
88+
89+ // When - log messages and flush buffers
90+ logger .debug ("Test message 1" );
91+ logger .debug ("Test message 2" );
92+
93+ Log4jLoggingManager manager = new Log4jLoggingManager ();
94+ manager .flushBuffer ();
95+
96+ // Then - both appenders should have flushed their buffers
97+ File logFile = new File ("target/logfile.json" );
98+ assertThat (logFile ).exists ();
99+ String content = contentOf (logFile );
100+ // Each message should appear twice (once from each BufferingAppender)
101+ assertThat (content .split ("Test message 1" , -1 )).hasSize (3 ); // 2 occurrences = 3 parts
102+ assertThat (content .split ("Test message 2" , -1 )).hasSize (3 ); // 2 occurrences = 3 parts
103+ } finally {
104+ // Restore original configuration to prevent test interference
105+ ctx .setConfiguration (originalConfig );
106+ ctx .updateLoggers ();
107+ }
100108 }
101109
102110 @ AfterEach
0 commit comments