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