Fix intermittent test failure caused by not closing logger appropriately