The background field method for quantum gravity at two loops