This allows to log a timestamp for each entry, and avoids potential interference with other threads that could log concurrently.
This concludes backport of core#27009
https://github.com/bitcoin/bitcoin/pull/27009/commits/fe683f352480245add0b27fe7efef5fef4c1e8c3
Depends on D14921