Fixes #3968: Messages logged in shutdown functions are not handled