Lock log files before appending, to avoid race condition