Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
a47d8ec
convert audit loggers to ILogger
PhilBastian Jun 9, 2025
047420b
revert app.config checkins
PhilBastian Jun 9, 2025
ad7cc4a
use pascal case for structured logging
PhilBastian Jun 9, 2025
3534fd2
revert accidental checkin for primary instance
PhilBastian Jun 10, 2025
aec0e48
Merge remote-tracking branch 'origin/extensions.logging_spike' into e…
PhilBastian Jun 10, 2025
b6505e6
Apply suggestions from code review
PhilBastian Jun 10, 2025
2a0db48
fix build error
PhilBastian Jun 10, 2025
573d9a2
Merge remote-tracking branch 'origin/extensions.logging_spike' into e…
PhilBastian Jun 10, 2025
1041b4e
revert setupcommand to having a parameterless constructor for activat…
PhilBastian Jun 10, 2025
4f25d49
replace NServiceBus.logging in Audit.Persistence with Microsoft.Exten…
PhilBastian Jun 12, 2025
a8c746f
convert SC transports from NServiceBus.Logging to Microsoft.Extension…
PhilBastian Jun 12, 2025
42d01e7
remove signedassembly requirement so that infrastructure can be imported
PhilBastian Jun 15, 2025
96ec124
revert previous change and instead propogate signing back to servicec…
PhilBastian Jun 15, 2025
5aaabe6
fix signature of customisation classes that are dynamically created
PhilBastian Jun 16, 2025
67920ff
add ilogger to test services and remove direct construction with logger
PhilBastian Jun 16, 2025
b3c690a
get tests to use ilogger
PhilBastian Jun 16, 2025
66aaa02
Switch to .NET logging
jasontaylordev Jun 10, 2025
e2196e6
Work in progress
jasontaylordev Jun 12, 2025
e9f287e
Remove test code
jasontaylordev Jun 13, 2025
9b97c92
Improve logging format for storage space details
jasontaylordev Jun 17, 2025
005968d
Properly shutdown NLog in Program.cs
jasontaylordev Jun 17, 2025
49ba86c
Remove Seq logging and prepare for .NET logging migration
jasontaylordev Jun 17, 2025
938c963
Update LogLevel format
jasontaylordev Jun 17, 2025
fb7f77e
Update LogLevel format in logging settings
jasontaylordev Jun 17, 2025
6c713bb
Merge branch 'master' into extensions.logging_transports
PhilBastian Jun 17, 2025
40eef99
Merge branch 'logging-spike-jt' into extensions.logging_transports
PhilBastian Jun 17, 2025
07d5606
enable adding test logging provider as part of loggerutils and create…
PhilBastian Jun 17, 2025
a843701
add ability to select logging provider from config
PhilBastian Jun 17, 2025
3e59886
handle setting not existing
PhilBastian Jun 17, 2025
ab580f6
change logmanager logger factory to the standard one now used by the …
PhilBastian Jun 17, 2025
3e16970
ensure logger for transport tests
PhilBastian Jun 18, 2025
a8a3061
Convert SC primary instance loggers to ILogger (#5019)
abparticular Jun 18, 2025
c92f803
domain events and persister loggers
PhilBastian Jun 18, 2025
dce6435
Merge branch 'master' into extensions.logging_spike
PhilBastian Jun 18, 2025
cc33a71
convert SC transports from NServiceBus.Logging to Microsoft.Extension…
PhilBastian Jun 18, 2025
416258d
Merge branch 'extensions.logging_spike' into extensions.logging_remai…
PhilBastian Jun 18, 2025
479d409
set default to nlog and pass loglevel to test context
PhilBastian Jun 19, 2025
c3c3de4
default to nLog
PhilBastian Jun 19, 2025
316516e
replace logmanager usage in persistence
PhilBastian Jun 19, 2025
6df6fd2
cleanup remaining references to LogManager
PhilBastian Jun 19, 2025
e37e282
missing files from last checkin
PhilBastian Jun 19, 2025
4485d7b
fix different dependency version test failure
PhilBastian Jun 20, 2025
4b80ba3
move loggerutil setup before first static logger usage
PhilBastian Jun 20, 2025
1200d13
Merge branch 'extensions.logging_spike' into extensions.logging_remai…
PhilBastian Jun 20, 2025
92b99b0
fix different dependency version test failure
PhilBastian Jun 20, 2025
9ab9af6
remove/refactor remaining references to LogManager (#5023)
PhilBastian Jun 20, 2025
39039ed
add logging config to all services
PhilBastian Jun 23, 2025
56a4635
enable seq url to be configured
PhilBastian Jun 24, 2025
ddb7568
allow seq url to be configured
PhilBastian Jun 24, 2025
b825edc
fix logger not being available in program.cs
PhilBastian Jun 24, 2025
7edf38f
make nlog level based on configuration again
PhilBastian Jun 24, 2025
ec9c21f
fix logging not being available during logging setup
PhilBastian Jun 25, 2025
912ef81
remove '.' from the end of log messages
PhilBastian Jun 26, 2025
e7bf499
remove unnecessary static logger
PhilBastian Jun 26, 2025
f0be16f
remove unnecessary checks since it's not around intensive log convers…
PhilBastian Jun 26, 2025
061ba55
remove unnecessary checks
PhilBastian Jun 27, 2025
22bcf4b
add opentelemetry as a logging provider option
PhilBastian Jun 27, 2025
ca52fa1
missing package reference
PhilBastian Jun 27, 2025
8b55728
Update src/ServiceControl/Monitoring/HeartbeatEndpointSettingsSyncHos…
PhilBastian Jun 27, 2025
43cc46c
Update src/ServiceControl/Monitoring/HeartbeatEndpointSettingsSyncHos…
PhilBastian Jun 27, 2025
ff85749
log text changes suggested in review
PhilBastian Jun 27, 2025
2fb0180
Merge remote-tracking branch 'origin/extensions.logging_spike' into e…
PhilBastian Jun 27, 2025
e7a28a2
Update src/ServiceControl.Infrastructure/LoggerUtil.cs
PhilBastian Jul 1, 2025
0533c6e
update method calls to match new name
PhilBastian Jul 1, 2025
2f1d97e
Enhanced `LoggerUtil` to include `DisposeLoggerFactories` for better …
jasontaylordev Jul 1, 2025
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
3 changes: 2 additions & 1 deletion src/Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
<PackageVersion Include="PublicApiGenerator" Version="11.4.6" />
<PackageVersion Include="RavenDB.Embedded" Version="6.2.5" />
<PackageVersion Include="ReactiveUI.WPF" Version="20.1.63" />
<PackageVersion Include="Seq.Extensions.Logging" Version="8.0.0" />
<PackageVersion Include="ServiceControl.Contracts" Version="5.0.0" />
<PackageVersion Include="System.Configuration.ConfigurationManager" Version="8.0.1" />
<PackageVersion Include="System.Diagnostics.PerformanceCounter" Version="8.0.1" />
Expand Down Expand Up @@ -91,4 +92,4 @@
<GlobalPackageReference Include="Microsoft.Build.CopyOnWrite" Version="1.0.334" />
<GlobalPackageReference Include="Particular.Packaging" Version="4.2.2" />
</ItemGroup>
</Project>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ async Task InitializeServiceControl(ScenarioContext context)

using (new DiagnosticTimer($"Creating infrastructure for {instanceName}"))
{
var setupCommand = new SetupCommand();
var setupCommand = new SetupCommand(LoggerUtil.CreateStaticLogger<SetupCommand>());
await setupCommand.Execute(new HostArguments([]), settings);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using NServiceBus;
using NServiceBus.Transport;
using NUnit.Framework;
using ServiceControl.Infrastructure;
using Transports;

class When_instance_is_setup
Expand Down Expand Up @@ -41,7 +42,7 @@ public async Task Should_provision_queues()
AssemblyLoadContextResolver = static _ => AssemblyLoadContext.Default
};

var setupCommand = new SetupCommand();
var setupCommand = new SetupCommand(LoggerUtil.CreateStaticLogger<SetupCommand>());
await setupCommand.Execute(new HostArguments([]), settings);

Assert.That(FakeTransport.QueuesCreated, Is.EquivalentTo(new[]
Expand Down
38 changes: 19 additions & 19 deletions src/ServiceControl.Audit/Auditing/AuditIngestion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
using Infrastructure.Settings;
using Metrics;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using NServiceBus;
using NServiceBus.Logging;
using NServiceBus.Transport;
using Persistence;
using Persistence.UnitOfWork;
Expand All @@ -27,7 +27,8 @@ public AuditIngestion(
AuditIngestor auditIngestor,
IAuditIngestionUnitOfWorkFactory unitOfWorkFactory,
IHostApplicationLifetime applicationLifetime,
IngestionMetrics metrics
IngestionMetrics metrics,
ILogger<AuditIngestion> logger
)
{
inputEndpoint = settings.AuditQueue;
Expand All @@ -38,7 +39,7 @@ IngestionMetrics metrics
this.settings = settings;
this.applicationLifetime = applicationLifetime;
this.metrics = metrics;

this.logger = logger;
if (!transportSettings.MaxConcurrency.HasValue)
{
throw new ArgumentException("MaxConcurrency is not set in TransportSettings");
Expand All @@ -54,7 +55,7 @@ IngestionMetrics metrics
FullMode = BoundedChannelFullMode.Wait
});

errorHandlingPolicy = new AuditIngestionFaultPolicy(failedImportsStorage, settings.LoggingSettings, OnCriticalError, metrics);
errorHandlingPolicy = new AuditIngestionFaultPolicy(failedImportsStorage, settings.LoggingSettings, OnCriticalError, metrics, logger);

watchdog = new Watchdog(
"audit message ingestion",
Expand All @@ -69,7 +70,7 @@ IngestionMetrics metrics

Task OnCriticalError(string failure, Exception exception)
{
logger.Fatal($"OnCriticalError. '{failure}'", exception);
logger.LogCritical(exception, "OnCriticalError. '{Failure}'", failure);
return watchdog.OnFailure(failure);
}

Expand All @@ -81,7 +82,7 @@ async Task EnsureStarted(CancellationToken cancellationToken)

var canIngest = unitOfWorkFactory.CanIngestMore();

logger.DebugFormat("Ensure started {0}", canIngest);
logger.LogDebug("Ensure started {CanIngest}", canIngest);

if (canIngest)
{
Expand Down Expand Up @@ -115,13 +116,13 @@ async Task SetUpAndStartInfrastructure(CancellationToken cancellationToken)
{
if (messageReceiver != null)
{
logger.Debug("Infrastructure already Started");
logger.LogDebug("Infrastructure already Started");
return;
}

try
{
logger.Info("Starting infrastructure");
logger.LogInformation("Starting infrastructure");
transportInfrastructure = await transportCustomization.CreateTransportInfrastructure(
inputEndpoint,
transportSettings,
Expand All @@ -136,11 +137,11 @@ async Task SetUpAndStartInfrastructure(CancellationToken cancellationToken)
await auditIngestor.VerifyCanReachForwardingAddress(cancellationToken);
await messageReceiver.StartReceive(cancellationToken);

logger.Info(LogMessages.StartedInfrastructure);
logger.LogInformation(LogMessages.StartedInfrastructure);
}
catch (Exception e)
{
logger.Error("Failed to start infrastructure", e);
logger.LogError(e, "Failed to start infrastructure");
throw;
}
}
Expand All @@ -149,13 +150,13 @@ async Task StopAndTeardownInfrastructure(CancellationToken cancellationToken)
{
if (transportInfrastructure == null)
{
logger.Debug("Infrastructure already Stopped");
logger.LogDebug("Infrastructure already Stopped");
return;
}

try
{
logger.Info("Stopping infrastructure");
logger.LogInformation("Stopping infrastructure");
try
{
if (messageReceiver != null)
Expand All @@ -171,11 +172,11 @@ async Task StopAndTeardownInfrastructure(CancellationToken cancellationToken)
messageReceiver = null;
transportInfrastructure = null;

logger.Info(LogMessages.StoppedInfrastructure);
logger.LogInformation(LogMessages.StoppedInfrastructure);
}
catch (Exception e)
{
logger.Error("Failed to stop infrastructure", e);
logger.LogError(e, "Failed to stop infrastructure");
throw;
}
}
Expand Down Expand Up @@ -254,11 +255,11 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken)

if (e is OperationCanceledException && stoppingToken.IsCancellationRequested)
{
logger.Info("Batch cancelled", e);
logger.LogInformation(e, "Batch cancelled");
break;
}

logger.Info("Ingesting messages failed", e);
logger.LogInformation(e, "Ingesting messages failed");
}
finally
{
Expand Down Expand Up @@ -291,7 +292,7 @@ public override async Task StopAsync(CancellationToken cancellationToken)
}
catch (OperationCanceledException e) when (cancellationToken.IsCancellationRequested)
{
logger.Info("Shutdown cancelled", e);
logger.LogInformation(e, "Shutdown cancelled");
}
}
}
Expand All @@ -313,8 +314,7 @@ public override async Task StopAsync(CancellationToken cancellationToken)
readonly Watchdog watchdog;
readonly IHostApplicationLifetime applicationLifetime;
readonly IngestionMetrics metrics;

static readonly ILog logger = LogManager.GetLogger<AuditIngestion>();
readonly ILogger<AuditIngestion> logger;

internal static class LogMessages
{
Expand Down
22 changes: 14 additions & 8 deletions src/ServiceControl.Audit/Auditing/AuditIngestionFaultPolicy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,27 @@
using System.Runtime.Versioning;
using System.Threading;
using System.Threading.Tasks;
using Configuration;
using Infrastructure;
using NServiceBus.Logging;
using Metrics;
using Microsoft.Extensions.Logging;
using NServiceBus.Transport;
using Persistence;
using Configuration;
using Metrics;
using ServiceControl.Infrastructure;

class AuditIngestionFaultPolicy
{
public AuditIngestionFaultPolicy(IFailedAuditStorage failedAuditStorage, LoggingSettings settings, Func<string, Exception, Task> onCriticalError, IngestionMetrics metrics)
public AuditIngestionFaultPolicy(
IFailedAuditStorage failedAuditStorage,
LoggingSettings settings,
Func<string, Exception, Task> onCriticalError,
IngestionMetrics metrics,
ILogger logger)
{
failureCircuitBreaker = new ImportFailureCircuitBreaker(onCriticalError);
this.failedAuditStorage = failedAuditStorage;
this.metrics = metrics;
this.logger = logger;

if (!AppEnvironment.RunningInContainer)
{
Expand Down Expand Up @@ -75,20 +81,20 @@ async Task StoreFailedMessageDocument(ErrorContext errorContext, CancellationTok

async Task DoLogging(Exception exception, FailedAuditImport failure, CancellationToken cancellationToken)
{
log.Error("Failed importing error message", exception);
logger.LogError(exception, "Failed importing error message");

// Write to storage
await failedAuditStorage.SaveFailedAuditImport(failure);

if (!AppEnvironment.RunningInContainer)
{
// Write to Log Path
var filePath = Path.Combine(logPath, failure.Id + ".txt");
var filePath = Path.Combine(logPath, $"{failure.Id}.txt");
await File.WriteAllTextAsync(filePath, failure.ExceptionInfo, cancellationToken);

if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
WriteToEventLog("A message import has failed. A log file has been written to " + filePath);
WriteToEventLog($"A message import has failed. A log file has been written to {filePath}");
}
}
}
Expand All @@ -107,5 +113,5 @@ void WriteToEventLog(string message)
readonly string logPath;
readonly ImportFailureCircuitBreaker failureCircuitBreaker;

static readonly ILog log = LogManager.GetLogger<AuditIngestionFaultPolicy>();
readonly ILogger logger;
}
14 changes: 8 additions & 6 deletions src/ServiceControl.Audit/Auditing/AuditIngestor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
using System.Threading;
using System.Threading.Tasks;
using Infrastructure.Settings;
using Microsoft.Extensions.Logging;
using Monitoring;
using NServiceBus;
using NServiceBus.Logging;
using NServiceBus.Routing;
using NServiceBus.Transport;
using Persistence.UnitOfWork;
Expand All @@ -25,12 +25,13 @@ public AuditIngestor(
IEnumerable<IEnrichImportedAuditMessages> auditEnrichers, // allows extending message enrichers with custom enrichers registered in the DI container
IMessageSession messageSession,
Lazy<IMessageDispatcher> messageDispatcher,
ITransportCustomization transportCustomization
ITransportCustomization transportCustomization,
ILogger<AuditIngestor> logger
)
{
this.settings = settings;
this.messageDispatcher = messageDispatcher;

this.logger = logger;
var enrichers = new IEnrichImportedAuditMessages[] { new MessageTypeEnricher(), new EnrichWithTrackingIds(), new ProcessingStatisticsEnricher(), new DetectNewEndpointsFromAuditImportsEnricher(endpointInstanceMonitoring), new DetectSuccessfulRetriesEnricher(), new SagaRelationshipsEnricher() }.Concat(auditEnrichers).ToArray();

logQueueAddress = transportCustomization.ToTransportQualifiedQueueName(settings.AuditLogQueue);
Expand All @@ -39,7 +40,8 @@ ITransportCustomization transportCustomization
unitOfWorkFactory,
enrichers,
messageSession,
messageDispatcher
messageDispatcher,
logger
);
}

Expand All @@ -61,7 +63,7 @@ public async Task Ingest(List<MessageContext> contexts, CancellationToken cancel
}
catch (Exception e)
{
Log.Warn("Forwarding messages failed", e);
logger.LogWarning(e, "Forwarding messages failed");

// making sure to rethrow so that all messages get marked as failed
throw;
Expand Down Expand Up @@ -129,6 +131,6 @@ public async Task VerifyCanReachForwardingAddress(CancellationToken cancellation
readonly Lazy<IMessageDispatcher> messageDispatcher;
readonly string logQueueAddress;

static readonly ILog Log = LogManager.GetLogger<AuditIngestor>();
readonly ILogger logger;
}
}
Loading
Loading