Add closing and flushing of logging handlers
Add closing and flushing of logging handlers

Summary:
> In order for BitcoinTestFramework to correctly restart after shutdown, the previous logging handlers need to be removed, or else logging will continue in the previous temp directory.
> "Flush" ensures buffers are emptied, and "close"ensures file handler close logging file.

This is a backport of Core [[https://github.com/bitcoin/bitcoin/pull/17288 | PR17288]] [3/8]
https://github.com/bitcoin/bitcoin/pull/17288/commits/6f40820757d25ff1ccfdfcbdf2b45b8b65308010

Depends on D8242

Test Plan: `ninja && ninja check`

Reviewers: O1 Bitcoin ABC, #bitcoin_abc, Fabien

Reviewed By: O1 Bitcoin ABC, #bitcoin_abc, Fabien

Differential Revision: https://reviews.bitcoinabc.org/D8243

Bitcoin-ABC/bitcoin-abc,Bitcoin-ABC/bitcoin-abc,Bitcoin-ABC/bitcoin-abc,Bitcoin-ABC/bitcoin-abc,Bitcoin-ABC/bitcoin-abc,Bitcoin-ABC/bitcoin-abc,Bitcoin-ABC/bitcoin-abc,Bitcoin-ABC/bitcoin-abc,Bitcoin-ABC/bitcoin-abc,Bitcoin-ABC/bitcoin-abc,Bitcoin-ABC/bitcoin-abc,Bitcoin-ABC/bitcoin-abc,Bitcoin-ABC/bitcoin-abc