Refactor LoggingAgent.
More refactorings.
Add a workaround for issue #915.