diff --git a/core/lib/Drupal/Core/Database/Log.php b/core/lib/Drupal/Core/Database/Log.php
index 13066f1..568cd11 100644
--- a/core/lib/Drupal/Core/Database/Log.php
+++ b/core/lib/Drupal/Core/Database/Log.php
@@ -185,8 +185,7 @@ public function findCaller() {
    *   Namespace of the database connection.
    */
   protected function getConnectionNamespace() {
-    $connection_class = get_class(Database::getConnection($this->connectionKey));
-    return substr($connection_class, 0, strrpos($connection_class, '\\'));
+    return Database::getConnection($this->connectionKey)->getConnectionOptions()['namespace'];
   }
 
   /**
