Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
using Azure.Storage.Blobs;
using Azure.Storage.Blobs.Models;
using Microsoft.Extensions.Logging;
using Paramore.Brighter.Logging;
using Microsoft.Extensions.Logging.Abstractions;

namespace Paramore.Brighter.Storage.Azure;

public class AzureBlobArchiveProvider(AzureBlobArchiveProviderOptions options) : IAmAnArchiveProvider
public class AzureBlobArchiveProvider(AzureBlobArchiveProviderOptions options, ILoggerFactory? loggerFactory = null) : IAmAnArchiveProvider
{
private readonly BlobContainerClient _containerClient = new BlobContainerClient(options.BlobContainerUri, options.TokenCredential);
private readonly ILogger _logger = ApplicationLogging.CreateLogger<AzureBlobArchiveProvider>();
private readonly ILogger _logger = (loggerFactory ?? NullLoggerFactory.Instance).CreateLogger<AzureBlobArchiveProvider>();

/// <summary>
/// Send a Message to the archive provider
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ THE SOFTWARE. */
using System.Threading.Tasks;
using Microsoft.Data.SqlClient;
using Microsoft.Extensions.Logging;
using Paramore.Brighter.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using Paramore.Brighter.Observability;

namespace Paramore.Brighter.BoxProvisioning.MsSql;
Expand Down Expand Up @@ -65,9 +65,10 @@ public MsSqlBoxMigrationRunner(
ILogger? logger = null,
TimeSpan? lockTimeout = null,
IAmABrighterTracer? tracer = null,
MigrationHistoryScope scope = MigrationHistoryScope.Global)
MigrationHistoryScope scope = MigrationHistoryScope.Global,
ILoggerFactory? loggerFactory = null)
: base(detectionHelper, catalog, configuration, lockTimeout ?? TimeSpan.FromSeconds(30),
logger ?? ApplicationLogging.CreateLogger<MsSqlBoxMigrationRunner>(),
logger ?? (loggerFactory ?? NullLoggerFactory.Instance).CreateLogger<MsSqlBoxMigrationRunner>(),
tracer, scope)
{
_advisoryLock = advisoryLock ?? new MsSqlAdvisoryLock();
Expand All @@ -86,8 +87,9 @@ public MsSqlBoxMigrationRunner(
IMsSqlAdvisoryLock? advisoryLock = null,
ILogger? logger = null,
IAmABrighterTracer? tracer = null,
MigrationHistoryScope scope = MigrationHistoryScope.Global)
: this(new MsSqlBoxDetectionHelper(), catalog, configuration, advisoryLock, logger, lockTimeout, tracer, scope)
MigrationHistoryScope scope = MigrationHistoryScope.Global,
ILoggerFactory? loggerFactory = null)
: this(new MsSqlBoxDetectionHelper(), catalog, configuration, advisoryLock, logger, lockTimeout, tracer, scope, loggerFactory)
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ THE SOFTWARE. */
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using MySqlConnector;
using Paramore.Brighter.Logging;
using Paramore.Brighter.Observability;

namespace Paramore.Brighter.BoxProvisioning.MySql;
Expand Down Expand Up @@ -65,9 +65,10 @@ public MySqlBoxMigrationRunner(
ILogger? logger = null,
TimeSpan? lockTimeout = null,
IAmABrighterTracer? tracer = null,
MigrationHistoryScope scope = MigrationHistoryScope.Global)
MigrationHistoryScope scope = MigrationHistoryScope.Global,
ILoggerFactory? loggerFactory = null)
: base(detectionHelper, catalog, configuration, lockTimeout ?? TimeSpan.FromSeconds(30),
logger ?? ApplicationLogging.CreateLogger<MySqlBoxMigrationRunner>(),
logger ?? (loggerFactory ?? NullLoggerFactory.Instance).CreateLogger<MySqlBoxMigrationRunner>(),
tracer, scope)
{
_advisoryLock = advisoryLock ?? new MySqlAdvisoryLock();
Expand All @@ -86,8 +87,9 @@ public MySqlBoxMigrationRunner(
IMySqlAdvisoryLock? advisoryLock = null,
ILogger? logger = null,
IAmABrighterTracer? tracer = null,
MigrationHistoryScope scope = MigrationHistoryScope.Global)
: this(new MySqlBoxDetectionHelper(), catalog, configuration, advisoryLock, logger, lockTimeout, tracer, scope)
MigrationHistoryScope scope = MigrationHistoryScope.Global,
ILoggerFactory? loggerFactory = null)
: this(new MySqlBoxDetectionHelper(), catalog, configuration, advisoryLock, logger, lockTimeout, tracer, scope, loggerFactory)
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ THE SOFTWARE. */
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using Npgsql;
using Paramore.Brighter.Logging;
using Paramore.Brighter.PostgreSql;

namespace Paramore.Brighter.BoxProvisioning.PostgreSql;
Expand Down Expand Up @@ -71,15 +70,16 @@ private static string QuotedHistorySchema(string? historySchema)
}

/// <summary>
/// Initialises the detection helper with an optional logger. When unspecified, falls back
/// to <see cref="ApplicationLogging.CreateLogger{T}"/>. Existing callers that use the
/// parameterless form continue to work — the logger is currently only consumed for the
/// Initialises the detection helper with an optional logger. When unspecified, the logger is
/// sourced from the supplied <see cref="ILoggerFactory"/> (or
/// <see cref="NullLoggerFactory.Instance"/> when that is also null). Existing callers that use
/// the parameterless form continue to work — the logger is currently only consumed for the
/// rare <c>UndefinedTable</c>-swallow Debug emission in
/// <see cref="DoesHistoryExistAsync"/>; the helper remains a safe DI singleton.
/// </summary>
public PostgreSqlBoxDetectionHelper(ILogger? logger = null)
public PostgreSqlBoxDetectionHelper(ILogger? logger = null, ILoggerFactory? loggerFactory = null)
{
_logger = logger ?? ApplicationLogging.CreateLogger<PostgreSqlBoxDetectionHelper>();
_logger = logger ?? (loggerFactory ?? NullLoggerFactory.Instance).CreateLogger<PostgreSqlBoxDetectionHelper>();
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ THE SOFTWARE. */
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using Npgsql;
using Paramore.Brighter.Logging;
using Paramore.Brighter.Observability;
using Paramore.Brighter.PostgreSql;

Expand Down Expand Up @@ -65,9 +65,10 @@ public PostgreSqlBoxMigrationRunner(
ILogger? logger = null,
TimeSpan? lockTimeout = null,
IAmABrighterTracer? tracer = null,
MigrationHistoryScope scope = MigrationHistoryScope.Global)
MigrationHistoryScope scope = MigrationHistoryScope.Global,
ILoggerFactory? loggerFactory = null)
: base(detectionHelper, catalog, configuration, lockTimeout ?? TimeSpan.FromSeconds(30),
logger ?? ApplicationLogging.CreateLogger<PostgreSqlBoxMigrationRunner>(),
logger ?? (loggerFactory ?? NullLoggerFactory.Instance).CreateLogger<PostgreSqlBoxMigrationRunner>(),
tracer, scope)
{
_advisoryLock = advisoryLock ?? new PostgreSqlAdvisoryLock();
Expand All @@ -86,8 +87,9 @@ public PostgreSqlBoxMigrationRunner(
IPostgreSqlAdvisoryLock? advisoryLock = null,
ILogger? logger = null,
IAmABrighterTracer? tracer = null,
MigrationHistoryScope scope = MigrationHistoryScope.Global)
: this(new PostgreSqlBoxDetectionHelper(), catalog, configuration, advisoryLock, logger, lockTimeout, tracer, scope)
MigrationHistoryScope scope = MigrationHistoryScope.Global,
ILoggerFactory? loggerFactory = null)
: this(new PostgreSqlBoxDetectionHelper(), catalog, configuration, advisoryLock, logger, lockTimeout, tracer, scope, loggerFactory)
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ THE SOFTWARE. */
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using Paramore.Brighter.Inbox.Spanner;
using Paramore.Brighter.Logging;
using Paramore.Brighter.Observability;
using Paramore.Brighter.Outbox.Spanner;

Expand Down Expand Up @@ -86,12 +85,13 @@ public SpannerBoxMigrationRunner(
IAmABoxMigrationDetectionHelper<SpannerConnection, SpannerTransaction> detectionHelper,
IAmARelationalDatabaseConfiguration configuration,
IAmABrighterTracer? tracer = null,
ILogger? logger = null)
ILogger? logger = null,
ILoggerFactory? loggerFactory = null)
{
_detectionHelper = detectionHelper;
_configuration = configuration;
_tracer = tracer;
_logger = logger ?? ApplicationLogging.CreateLogger<SpannerBoxMigrationRunner>();
_logger = logger ?? (loggerFactory ?? NullLoggerFactory.Instance).CreateLogger<SpannerBoxMigrationRunner>();
}

/// <summary>
Expand All @@ -102,8 +102,9 @@ public SpannerBoxMigrationRunner(
public SpannerBoxMigrationRunner(
IAmARelationalDatabaseConfiguration configuration,
IAmABrighterTracer? tracer = null,
ILogger? logger = null)
: this(new SpannerBoxDetectionHelper(), configuration, tracer, logger)
ILogger? logger = null,
ILoggerFactory? loggerFactory = null)
: this(new SpannerBoxDetectionHelper(), configuration, tracer, logger, loggerFactory)
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ THE SOFTWARE. */
using System.Threading.Tasks;
using Microsoft.Data.Sqlite;
using Microsoft.Extensions.Logging;
using Paramore.Brighter.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using Paramore.Brighter.Observability;

namespace Paramore.Brighter.BoxProvisioning.Sqlite;
Expand Down Expand Up @@ -96,9 +96,10 @@ public SqliteBoxMigrationRunner(
TimeSpan? lockTimeout = null,
bool enableWalMode = true,
IAmABrighterTracer? tracer = null,
MigrationHistoryScope scope = MigrationHistoryScope.Global)
MigrationHistoryScope scope = MigrationHistoryScope.Global,
ILoggerFactory? loggerFactory = null)
: base(detectionHelper, catalog, configuration, lockTimeout ?? TimeSpan.FromSeconds(30),
logger ?? ApplicationLogging.CreateLogger<SqliteBoxMigrationRunner>(),
logger ?? (loggerFactory ?? NullLoggerFactory.Instance).CreateLogger<SqliteBoxMigrationRunner>(),
tracer, scope)
{
_enableWalMode = enableWalMode;
Expand All @@ -117,8 +118,9 @@ public SqliteBoxMigrationRunner(
TimeSpan lockTimeout,
bool enableWalMode = true,
IAmABrighterTracer? tracer = null,
MigrationHistoryScope scope = MigrationHistoryScope.Global)
: this(new SqliteBoxDetectionHelper(), catalog, configuration, logger: null, lockTimeout: lockTimeout, enableWalMode: enableWalMode, tracer: tracer, scope: scope)
MigrationHistoryScope scope = MigrationHistoryScope.Global,
ILoggerFactory? loggerFactory = null)
: this(new SqliteBoxDetectionHelper(), catalog, configuration, logger: null, lockTimeout: lockTimeout, enableWalMode: enableWalMode, tracer: tracer, scope: scope, loggerFactory: loggerFactory)
{
}

Expand Down
17 changes: 9 additions & 8 deletions src/Paramore.Brighter.BoxProvisioning/SqlBoxProvisioner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ THE SOFTWARE. */
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using Paramore.Brighter.Logging;
using Microsoft.Extensions.Logging.Abstractions;

namespace Paramore.Brighter.BoxProvisioning;

Expand All @@ -52,10 +52,8 @@ public abstract class SqlBoxProvisioner<TConnection, TTransaction>
where TConnection : DbConnection
where TTransaction : DbTransaction
{
// Static logger keeps the ctor surface unchanged across the 8 concrete provisioners; only
// exercised by the pre-lock-hint failure swallow below (Spec 0029 T-PERM).
private static readonly ILogger s_logger =
ApplicationLogging.CreateLogger<SqlBoxProvisioner<TConnection, TTransaction>>();
// Logger is only exercised by the pre-lock-hint failure swallow below (Spec 0029 T-PERM).
private readonly ILogger _logger;

private readonly IAmAVersionDetectingMigrationHelper<TConnection, TTransaction> _detectionHelper;
private readonly IAmABoxMigrationCatalog _catalog;
Expand All @@ -73,14 +71,17 @@ protected SqlBoxProvisioner(
IAmABoxPayloadModeValidator<TConnection> payloadValidator,
IAmARelationalDatabaseConfiguration configuration,
IAmABoxMigrationRunner migrationRunner,
BoxType boxType)
BoxType boxType,
ILoggerFactory? loggerFactory = null)
{
_detectionHelper = detectionHelper;
_catalog = catalog;
_payloadValidator = payloadValidator;
_configuration = configuration;
_migrationRunner = migrationRunner;
BoxType = boxType;
_logger = (loggerFactory ?? NullLoggerFactory.Instance)
.CreateLogger<SqlBoxProvisioner<TConnection, TTransaction>>();
}

/// <inheritdoc />
Expand Down Expand Up @@ -173,7 +174,7 @@ private async Task<BoxTableState> DetectTableStateAsync(
}
catch (DbException ex)
{
s_logger.LogDebug(ex,
_logger.LogDebug(ex,
"Pre-lock historyExists hint for '{Schema}.{Table}' unavailable; deferring to the runner's under-lock authoritative detection.",
EffectiveSchemaName, BoxTableName);
historyExists = false;
Expand Down Expand Up @@ -202,7 +203,7 @@ private async Task<BoxTableState> DetectTableStateAsync(
}
catch (DbException ex)
{
s_logger.LogDebug(ex,
_logger.LogDebug(ex,
"Pre-lock maxVersion hint for '{Schema}.{Table}' unavailable; deferring to the runner's under-lock authoritative detection.",
EffectiveSchemaName, BoxTableName);
maxVersion = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ THE SOFTWARE. */
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using Microsoft.Extensions.Options;
using Paramore.Brighter.FeatureSwitch;
using Paramore.Brighter.Logging;
using System.Text.Json;
using Paramore.Brighter.CircuitBreaker;
using Paramore.Brighter.JsonConverters;
Expand Down Expand Up @@ -680,11 +680,9 @@ private static INeedInstrumentation AddEventBus(

private static IAmACommandProcessor BuildCommandProcessor(IServiceProvider provider)
{
var loggerFactory = provider.GetService<ILoggerFactory>();
//if not supplied, use the default logger factory, which has no providers
if (loggerFactory != null)
ApplicationLogging.LoggerFactory = loggerFactory;

//Resolve the container's logger factory and flow it through the builder as an instance,
//rather than copying it into a process-wide static (which would be disposed with the container).
var loggerFactory = provider.GetService<ILoggerFactory>() ?? NullLoggerFactory.Instance;

var options = provider.GetRequiredService<IBrighterOptions>();
var subscriberRegistry = provider.GetRequiredService<ServiceCollectionSubscriberRegistry>();
Expand Down Expand Up @@ -712,6 +710,7 @@ private static IAmACommandProcessor BuildCommandProcessor(IServiceProvider provi
.ConfigureInstrumentation(provider.GetService<IAmABrighterTracer>(), options.InstrumentationOptions)
.RequestContextFactory(provider.GetRequiredService<IAmARequestContextFactory>())
.RequestSchedulerFactory(provider.GetRequiredService<IAmARequestSchedulerFactory>())
.ConfigureLogging(loggerFactory)
.Build();

var eventBusConfiguration = provider.GetService<IAmProducersConfiguration>();
Expand Down Expand Up @@ -751,7 +750,8 @@ private static IAmACommandProcessor BuildCommandProcessor(IServiceProvider provi
busConfiguration.MaxOutStandingCheckInterval,
busConfiguration.OutBoxBag,
TimeProvider.System,
busConfiguration.InstrumentationOptions);
busConfiguration.InstrumentationOptions,
serviceProvider.GetService<ILoggerFactory>() ?? NullLoggerFactory.Instance);
}

/// <summary>
Expand Down
13 changes: 8 additions & 5 deletions src/Paramore.Brighter.Inbox.MsSql/MsSqlInbox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ THE SOFTWARE. */
using System;
using System.Data;
using Microsoft.Data.SqlClient;
using Paramore.Brighter.Logging;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using Paramore.Brighter.MsSql;
using Paramore.Brighter.Observability;

Expand All @@ -45,18 +46,20 @@ public class MsSqlInbox : RelationalDatabaseInbox
/// </summary>
/// <param name="configuration">The configuration.</param>
/// <param name="connectionProvider">The Connection Provider.</param>
public MsSqlInbox(IAmARelationalDatabaseConfiguration configuration, IAmARelationalDbConnectionProvider connectionProvider)
/// <param name="logger">The logger to use; defaults to a null logger when not supplied</param>
public MsSqlInbox(IAmARelationalDatabaseConfiguration configuration, IAmARelationalDbConnectionProvider connectionProvider, ILogger<MsSqlInbox>? logger = null)
: base(DbSystem.MsSql, configuration, connectionProvider,
new MsSqlQueries(), ApplicationLogging.CreateLogger<MsSqlInbox>())
new MsSqlQueries(), logger ?? NullLogger<MsSqlInbox>.Instance)
{
}

/// <summary>
/// Initializes a new instance of the <see cref="MsSqlInbox" /> class.
/// </summary>
/// <param name="configuration">The configuration.</param>
public MsSqlInbox(IAmARelationalDatabaseConfiguration configuration) : this(configuration,
new MsSqlConnectionProvider(configuration))
/// <param name="logger">The logger to use; defaults to a null logger when not supplied</param>
public MsSqlInbox(IAmARelationalDatabaseConfiguration configuration, ILogger<MsSqlInbox>? logger = null) : this(configuration,
new MsSqlConnectionProvider(configuration), logger)
{
}

Expand Down
15 changes: 9 additions & 6 deletions src/Paramore.Brighter.Inbox.MySql/MySqlInbox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ THE SOFTWARE. */

using System;
using System.Data;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using MySqlConnector;
using Paramore.Brighter.Logging;
using Paramore.Brighter.MySql;
using Paramore.Brighter.Observability;

Expand All @@ -44,18 +45,20 @@ public class MySqlInbox : RelationalDatabaseInbox
/// </summary>
/// <param name="configuration">The configuration.</param>
/// <param name="connectionProvider">The Connection Provider.</param>
public MySqlInbox(IAmARelationalDatabaseConfiguration configuration, IAmARelationalDbConnectionProvider connectionProvider)
: base(DbSystem.MySql, configuration, connectionProvider,
new MySqlQueries(), ApplicationLogging.CreateLogger<MySqlInbox>())
/// <param name="logger">The logger to use; defaults to a null logger when not supplied</param>
public MySqlInbox(IAmARelationalDatabaseConfiguration configuration, IAmARelationalDbConnectionProvider connectionProvider, ILogger<MySqlInbox>? logger = null)
: base(DbSystem.MySql, configuration, connectionProvider,
new MySqlQueries(), logger ?? NullLogger<MySqlInbox>.Instance)
{
}

/// <summary>
/// Initializes a new instance of the <see cref="MySqlInbox" /> class.
/// </summary>
/// <param name="configuration">The configuration.</param>
public MySqlInbox(IAmARelationalDatabaseConfiguration configuration) : this(configuration,
new MySqlConnectionProvider(configuration))
/// <param name="logger">The logger to use; defaults to a null logger when not supplied</param>
public MySqlInbox(IAmARelationalDatabaseConfiguration configuration, ILogger<MySqlInbox>? logger = null) : this(configuration,
new MySqlConnectionProvider(configuration), logger)
{
}

Expand Down
Loading
Loading