From fc6b11081a780ecbd4f58700fa8ba9e09f1dd1ae Mon Sep 17 00:00:00 2001 From: "Jeremy D. Miller" Date: Wed, 28 Feb 2024 10:11:15 -0600 Subject: [PATCH] Better way of adding logging to internal NpgsqlDataSource. Closes GH-2966 --- src/Marten/StoreOptions.cs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/Marten/StoreOptions.cs b/src/Marten/StoreOptions.cs index 1f8bac5e3e..66ffd8ad15 100644 --- a/src/Marten/StoreOptions.cs +++ b/src/Marten/StoreOptions.cs @@ -116,6 +116,18 @@ public StoreOptions() ResiliencePipeline = strategy; #endregion + + // Add logging into our NpgsqlDataSource + NpgsqlDataSourceFactory = new DefaultNpgsqlDataSourceFactory(connectionString => + { + var builder = new NpgsqlDataSourceBuilder(connectionString); + if (LogFactory != null) + { + builder.UseLoggerFactory(LogFactory); + } + + return builder; + }); } /// @@ -334,7 +346,7 @@ public ITenancy Tenancy private Lazy? _tenancy; private Func _npgsqlDataSourceBuilderFactory = DefaultNpgsqlDataSourceBuilderFactory; - private INpgsqlDataSourceFactory _npgsqlDataSourceFactory = new DefaultNpgsqlDataSourceFactory(); + private INpgsqlDataSourceFactory _npgsqlDataSourceFactory; private readonly IList _compiledQueryTypes = new List(); private int _applyChangesLockId = 4004; private bool _shouldApplyChangesOnStartup = false;