Fix race condition in Logger::GetLoggers.

Fixes #5341