From 50252815a69809402e1d138c4ab3d93654484136 Mon Sep 17 00:00:00 2001 From: Andrei Timar Date: Sun, 13 Sep 2026 09:15:07 +0300 Subject: [PATCH] feat(backend): improve logging for gateway and analysis services --- .../RunScriptBackgroundService.cs | 43 +++++++++- .../Analysis/Adapters/Analysis.Web/Program.cs | 19 ++++- .../Service.Analysis/InstallPluginService.cs | 30 ++++++- .../Service.Analysis/LoadModelFilesService.cs | 15 +++- .../Service.Analysis/RunAnalysisService.cs | 36 +++++++-- .../Service.Analysis/RunScriptService.cs | 38 ++++++++- .../Extensions/SerilogExtensions.cs | 16 ++-- .../Entity/MongodbProjectModel.cs | 2 +- .../Rest/TriggerInstanceAnalysisAdapter.cs | 81 ++++++++++++++----- ...eteProjectLevelPluginsBackgroundService.cs | 8 ++ ...sForAllocatedInstancesBackgroundService.cs | 9 +++ .../src/Gateway/Adapters/Web/Program.cs | 23 +++++- .../Adapters/Web/appsettings.Development.json | 6 +- .../src/Gateway/Adapters/Web/appsettings.json | 3 +- .../Analysis/AnalysisStatusMonitorService.cs | 9 ++- .../Context/ClearInstanceContextService.cs | 11 ++- .../Context/LinkInstanceContextService.cs | 19 ++++- .../Context/LoadInstanceContextService.cs | 19 ++++- .../Context/ReloadInstanceContextService.cs | 18 ++++- .../Service.Gateway/CreateProjectService.cs | 21 ++++- .../Service.Gateway/DeleteProjectService.cs | 17 +++- .../BundlePluginInstaller.cs | 27 ++++--- .../Plugins.Installer/PluginUninstaller.cs | 9 ++- .../Plugins.Installer/PluginZipProcessor.cs | 27 ++++++- .../RunScriptBackgroundServiceTest.cs | 7 +- .../InstallPluginServiceTest.cs | 4 +- .../LoadModelFilesServiceTest.cs | 4 +- .../RunAnalysisServiceTest.cs | 4 +- .../RunScriptServiceTest.cs | 4 +- .../Service.Analysis.Tests.csproj | 1 + .../TriggerInstanceAnalysisAdapterTest.cs | 4 +- .../ClearInstanceContextServiceTest.cs | 6 +- .../Context/LinkInstanceContextServiceTest.cs | 6 +- .../Context/LoadInstanceContextServiceTest.cs | 4 +- .../ReloadInstanceContextServiceTest.cs | 4 +- .../CreateProjectServiceTests.cs | 6 +- .../DeleteProjectServiceTests.cs | 4 +- 37 files changed, 475 insertions(+), 89 deletions(-) diff --git a/ScriptBeeWebApp/src/Analysis/Adapters/Analysis.Web/BackgroundServices/RunScriptBackgroundService.cs b/ScriptBeeWebApp/src/Analysis/Adapters/Analysis.Web/BackgroundServices/RunScriptBackgroundService.cs index 6fd93991..e0f49007 100644 --- a/ScriptBeeWebApp/src/Analysis/Adapters/Analysis.Web/BackgroundServices/RunScriptBackgroundService.cs +++ b/ScriptBeeWebApp/src/Analysis/Adapters/Analysis.Web/BackgroundServices/RunScriptBackgroundService.cs @@ -6,15 +6,52 @@ namespace ScriptBee.Analysis.Web.BackgroundServices; public class RunScriptBackgroundService( Channel runScriptChannel, - IRunScriptService runScriptService + IRunScriptService runScriptService, + ILogger logger ) : BackgroundService { protected override async Task ExecuteAsync(CancellationToken stoppingToken) { + logger.LogInformation("Run Script Background Service is starting"); + while (await runScriptChannel.Reader.WaitToReadAsync(stoppingToken)) { - var request = await runScriptChannel.Reader.ReadAsync(stoppingToken); - await runScriptService.RunAsync(request, stoppingToken); + RunScriptRequest? request = null; + try + { + request = await runScriptChannel.Reader.ReadAsync(stoppingToken); + + logger.LogInformation( + "Executing script {ScriptPath} for analysis {AnalysisId} on project {ProjectId}", + request.Script.File.Path, + request.AnalysisInfo.Id, + request.Script.ProjectId + ); + + await runScriptService.RunAsync(request, stoppingToken); + + logger.LogInformation( + "Script {ScriptPath} completed for analysis {AnalysisId}", + request.Script.File.Path, + request.AnalysisInfo.Id + ); + } + catch (OperationCanceledException) when (stoppingToken.IsCancellationRequested) + { + logger.LogInformation("Run Script Background Service is stopping"); + break; + } + catch (Exception e) + { + logger.LogError( + e, + "Unhandled error while executing script {ScriptPath} for analysis {AnalysisId}", + request?.Script.File.Path, + request?.AnalysisInfo.Id + ); + } } + + logger.LogInformation("Run Script Background Service has stopped"); } } diff --git a/ScriptBeeWebApp/src/Analysis/Adapters/Analysis.Web/Program.cs b/ScriptBeeWebApp/src/Analysis/Adapters/Analysis.Web/Program.cs index 4a06bf4f..2fb9f2fd 100644 --- a/ScriptBeeWebApp/src/Analysis/Adapters/Analysis.Web/Program.cs +++ b/ScriptBeeWebApp/src/Analysis/Adapters/Analysis.Web/Program.cs @@ -7,6 +7,7 @@ using ScriptBee.Common.Web.EndpointDefinition; using ScriptBee.Common.Web.Extensions; using Serilog; +using Serilog.Events; var builder = WebApplication.CreateBuilder(args); @@ -66,7 +67,23 @@ app.MapHealthChecksEndpoint(); -app.UseSerilogRequestLogging(); +app.UseSerilogRequestLogging(options => +{ + options.GetLevel = (ctx, _, ex) => + ex is not null ? LogEventLevel.Error + : ctx.Request.Path.StartsWithSegments("/health") ? LogEventLevel.Debug + : LogEventLevel.Information; + + options.EnrichDiagnosticContext = (diagnosticContext, httpContext) => + { + diagnosticContext.Set("RequestHost", httpContext.Request.Host.Value); + diagnosticContext.Set("RequestScheme", httpContext.Request.Scheme); + if (httpContext.Request.Headers.TryGetValue("X-Client-Id", out var clientId)) + { + diagnosticContext.Set("ClientId", clientId.ToString()); + } + }; +}); app.UseExceptionEndpoint(); diff --git a/ScriptBeeWebApp/src/Analysis/Application/Service.Analysis/InstallPluginService.cs b/ScriptBeeWebApp/src/Analysis/Application/Service.Analysis/InstallPluginService.cs index bbbfa000..25d880dc 100644 --- a/ScriptBeeWebApp/src/Analysis/Application/Service.Analysis/InstallPluginService.cs +++ b/ScriptBeeWebApp/src/Analysis/Application/Service.Analysis/InstallPluginService.cs @@ -1,3 +1,4 @@ +using Microsoft.Extensions.Logging; using OneOf; using OneOf.Types; using ScriptBee.Domain.Model.Plugins; @@ -13,13 +14,20 @@ public class InstallPluginService( IProjectManager projectManager, IPluginReader pluginReader, IPluginLoader pluginLoader, - IPluginPathProvider pluginPathProvider + IPluginPathProvider pluginPathProvider, + ILogger logger ) : IInstallPluginUseCase { public OneOf InstallPlugin( PluginId pluginId ) { + logger.LogInformation( + "Installing plugin {PluginName} {PluginVersion} on analysis instance", + pluginId.Name, + pluginId.Version + ); + try { var projectId = ProjectId.FromValue(projectManager.GetProject().Id); @@ -30,14 +38,32 @@ PluginId pluginId if (plugin is null) { + logger.LogWarning( + "Plugin {PluginName} {PluginVersion} not found in project or global plugin paths", + pluginId.Name, + pluginId.Version + ); return new InvalidPluginError(pluginId); } pluginLoader.Load(plugin); + + logger.LogInformation( + "Plugin {PluginName} {PluginVersion} installed on analysis instance", + pluginId.Name, + pluginId.Version + ); + return new Success(); } - catch + catch (Exception e) { + logger.LogError( + e, + "Failed to install plugin {PluginName} {PluginVersion} on analysis instance", + pluginId.Name, + pluginId.Version + ); return new PluginInstallationError(pluginId); } } diff --git a/ScriptBeeWebApp/src/Analysis/Application/Service.Analysis/LoadModelFilesService.cs b/ScriptBeeWebApp/src/Analysis/Application/Service.Analysis/LoadModelFilesService.cs index d910ac47..6f2406fc 100644 --- a/ScriptBeeWebApp/src/Analysis/Application/Service.Analysis/LoadModelFilesService.cs +++ b/ScriptBeeWebApp/src/Analysis/Application/Service.Analysis/LoadModelFilesService.cs @@ -1,5 +1,6 @@ using DxWorks.ScriptBee.Plugin.Api; using DxWorks.ScriptBee.Plugin.Api.Model; +using Microsoft.Extensions.Logging; using ScriptBee.Artifacts; using ScriptBee.Domain.Model.File; using ScriptBee.Plugins.Loader; @@ -9,7 +10,8 @@ namespace ScriptBee.Service.Analysis; public class LoadModelFilesService( IProjectManager projectManager, IPluginRepository pluginRepository, - IFileModelService fileModelService + IFileModelService fileModelService, + ILogger logger ) : ILoadModelFilesService { public async Task LoadModelFiles( @@ -25,9 +27,14 @@ public async Task LoadModelFiles( if (modelLoader is null) { + logger.LogWarning( + "No model loader plugin found for loader '{LoaderId}' — files will be skipped", + loader + ); continue; } + logger.LogDebug("Loading model files with loader '{LoaderId}'", loader); await LoadModelFiles(fileIds, modelLoader, loader, loadModels, cancellationToken); } } @@ -53,6 +60,12 @@ CancellationToken cancellationToken cancellationToken: cancellationToken ); + logger.LogDebug( + "Loader '{LoaderId}' produced {TypeCount} model type(s)", + loader, + dictionary.Count + ); + projectManager.AddToGivenProject(dictionary, modelLoader.GetName()); AddToLoadedModels(dictionary, loader, loadModels); diff --git a/ScriptBeeWebApp/src/Analysis/Application/Service.Analysis/RunAnalysisService.cs b/ScriptBeeWebApp/src/Analysis/Application/Service.Analysis/RunAnalysisService.cs index 39578faf..c14b4fdb 100644 --- a/ScriptBeeWebApp/src/Analysis/Application/Service.Analysis/RunAnalysisService.cs +++ b/ScriptBeeWebApp/src/Analysis/Application/Service.Analysis/RunAnalysisService.cs @@ -1,5 +1,6 @@ using System.Threading.Channels; using DxWorks.ScriptBee.Plugin.Api; +using Microsoft.Extensions.Logging; using OneOf; using ScriptBee.Analysis; using ScriptBee.Artifacts; @@ -19,7 +20,8 @@ public class RunAnalysisService( IGetScripts getScripts, IPluginRepository pluginRepository, Channel runScriptChannel, - InstanceInformation instanceInformation + InstanceInformation instanceInformation, + ILogger logger ) : IRunAnalysisUseCase { public async Task Run( @@ -27,12 +29,23 @@ public async Task Run( CancellationToken cancellationToken = default ) { + logger.LogInformation( + "Starting analysis for script {ScriptId} on project {ProjectId}", + command.ScriptId, + command.ProjectId + ); + var scriptResult = await getScripts.Get(command.ScriptId, cancellationToken); return await scriptResult.Match( async script => await Run(script, cancellationToken), async error => - await createAnalysis.Create( + { + logger.LogWarning( + "Script {ScriptId} not found — analysis will be recorded as failed to start", + command.ScriptId + ); + return await createAnalysis.Create( AnalysisInfo.FailedToStart( new AnalysisId(guidProvider.NewGuid()), command.ProjectId, @@ -42,7 +55,8 @@ await createAnalysis.Create( error.ToString() ), cancellationToken - ) + ); + } ); } @@ -56,7 +70,12 @@ private async Task Run( return await scriptRunnerResult.Match( async runner => await Run(runner, script, cancellationToken), async error => - await createAnalysis.Create( + { + logger.LogWarning( + "No script runner found for language {Language} — analysis will be recorded as failed to start", + script.ScriptLanguage.Name + ); + return await createAnalysis.Create( AnalysisInfo.FailedToStart( new AnalysisId(guidProvider.NewGuid()), script.ProjectId, @@ -66,7 +85,8 @@ await createAnalysis.Create( error.ToString() ), cancellationToken - ) + ); + } ); } @@ -87,6 +107,12 @@ private async Task Run( cancellationToken ); + logger.LogInformation( + "Analysis {AnalysisId} created — queuing script {ScriptPath} for execution", + analysisInfo.Id, + script.File.Path + ); + await runScriptChannel.Writer.WriteAsync( new RunScriptRequest(scriptRunner, script, analysisInfo), cancellationToken diff --git a/ScriptBeeWebApp/src/Analysis/Application/Service.Analysis/RunScriptService.cs b/ScriptBeeWebApp/src/Analysis/Application/Service.Analysis/RunScriptService.cs index 771ded9f..bba03a93 100644 --- a/ScriptBeeWebApp/src/Analysis/Application/Service.Analysis/RunScriptService.cs +++ b/ScriptBeeWebApp/src/Analysis/Application/Service.Analysis/RunScriptService.cs @@ -1,6 +1,7 @@ using System.Text; using DxWorks.ScriptBee.Plugin.Api; using DxWorks.ScriptBee.Plugin.Api.Services; +using Microsoft.Extensions.Logging; using ScriptBee.Analysis; using ScriptBee.Artifacts; using ScriptBee.Common; @@ -18,7 +19,8 @@ public sealed class RunScriptService( IDateTimeProvider dateTimeProvider, IGuidProvider guidProvider, IPluginRepository pluginRepository, - IProjectManager projectManager + IProjectManager projectManager, + ILogger logger ) : IRunScriptService { public async Task RunAsync( @@ -38,7 +40,14 @@ await scriptContent.Match( await RunScript(request, content, cancellationToken); }, async error => - await UpdateAnalysisFileNotFound(request.AnalysisInfo, error, cancellationToken) + { + logger.LogWarning( + "Script file not found for analysis {AnalysisId}: {Error}", + request.AnalysisInfo.Id, + error + ); + await UpdateAnalysisFileNotFound(request.AnalysisInfo, error, cancellationToken); + } ); } @@ -48,6 +57,12 @@ private async Task RunScript( CancellationToken cancellationToken ) { + logger.LogDebug( + "Saving script file snapshot for analysis {AnalysisId} (language: {Language})", + request.AnalysisInfo.Id, + request.Script.ScriptLanguage.Name + ); + var metadata = new HistoricalScriptMetadata( request.Script.File.Path, request.Script.ScriptLanguage.Name, @@ -59,6 +74,12 @@ CancellationToken cancellationToken var analysisInfo = request.AnalysisInfo with { ScriptFileId = scriptFileId }; await updateAnalysis.Update(analysisInfo, cancellationToken); + logger.LogDebug( + "Running script for analysis {AnalysisId} with runner {Runner}", + request.AnalysisInfo.Id, + request.ScriptRunner.GetType().Name + ); + var results = await RunScriptAsync( request.ScriptRunner, request.Script, @@ -66,6 +87,12 @@ CancellationToken cancellationToken cancellationToken ); + logger.LogDebug( + "Script execution finished for analysis {AnalysisId} — {ResultCount} result(s) produced", + request.AnalysisInfo.Id, + results.Count + ); + await updateAnalysis.Update( analysisInfo.Success(dateTimeProvider.UtcNow(), results), cancellationToken @@ -128,6 +155,13 @@ await scriptRunner.RunAsync( } catch (Exception e) { + logger.LogError( + e, + "Script runner threw an exception for script {ScriptPath} (language: {Language})", + script.File.Path, + script.ScriptLanguage.Name + ); + var runErrorId = await SaveStringContentToFile( e.Message, null, diff --git a/ScriptBeeWebApp/src/Common/Common.Web/Extensions/SerilogExtensions.cs b/ScriptBeeWebApp/src/Common/Common.Web/Extensions/SerilogExtensions.cs index bbd8d5a8..8ad0acec 100644 --- a/ScriptBeeWebApp/src/Common/Common.Web/Extensions/SerilogExtensions.cs +++ b/ScriptBeeWebApp/src/Common/Common.Web/Extensions/SerilogExtensions.cs @@ -9,12 +9,14 @@ public static class SerilogExtensions { public static IServiceCollection AddSerilog(this IServiceCollection services) { - var serilogLogger = new LoggerConfiguration() - .MinimumLevel.Override("Microsoft", LogEventLevel.Information) + Log.Logger = new LoggerConfiguration() + .MinimumLevel.Override("Microsoft", LogEventLevel.Warning) + .MinimumLevel.Override("System", LogEventLevel.Warning) .Enrich.FromLogContext() - .WriteTo.Console() - .CreateLogger(); - Log.Logger = serilogLogger; + .WriteTo.Console( + outputTemplate: "[{Timestamp:o}][{Level:u3}][bootstrap] {Message:lj}{NewLine}{Exception}" + ) + .CreateBootstrapLogger(); return services; } @@ -23,7 +25,9 @@ public static IHostBuilder UseSerilog(this IHostBuilder hostBuilder) { return hostBuilder.UseSerilog( (context, services, config) => - config.ReadFrom.Configuration(context.Configuration).ReadFrom.Services(services) + config.ReadFrom.Configuration(context.Configuration).ReadFrom.Services(services), + preserveStaticLogger: false, + writeToProviders: false ); } } diff --git a/ScriptBeeWebApp/src/Gateway/Adapters/Persistence.Mongodb.Gateway/Entity/MongodbProjectModel.cs b/ScriptBeeWebApp/src/Gateway/Adapters/Persistence.Mongodb.Gateway/Entity/MongodbProjectModel.cs index 8781697d..4e07a870 100644 --- a/ScriptBeeWebApp/src/Gateway/Adapters/Persistence.Mongodb.Gateway/Entity/MongodbProjectModel.cs +++ b/ScriptBeeWebApp/src/Gateway/Adapters/Persistence.Mongodb.Gateway/Entity/MongodbProjectModel.cs @@ -25,7 +25,7 @@ public ProjectDetails ToProjectDetails() ProjectId.FromValue(Id), Name, CreationDate, - SavedFiles.Select(v => v.ToFileData()).ToList(), + [.. SavedFiles.Select(v => v.ToFileData())], LoadedFiles.ToDictionary(x => x.Key, x => x.Value.Select(v => v.ToFileData()).ToList()), [.. Linkers], [.. InstalledPlugins.Select(x => x.ToPluginInstallationConfig())] diff --git a/ScriptBeeWebApp/src/Gateway/Adapters/Rest/TriggerInstanceAnalysisAdapter.cs b/ScriptBeeWebApp/src/Gateway/Adapters/Rest/TriggerInstanceAnalysisAdapter.cs index f52bd27c..090944a4 100644 --- a/ScriptBeeWebApp/src/Gateway/Adapters/Rest/TriggerInstanceAnalysisAdapter.cs +++ b/ScriptBeeWebApp/src/Gateway/Adapters/Rest/TriggerInstanceAnalysisAdapter.cs @@ -1,3 +1,4 @@ +using Microsoft.Extensions.Logging; using Refit; using ScriptBee.Domain.Model.Analysis; using ScriptBee.Domain.Model.Instance; @@ -9,8 +10,10 @@ namespace ScriptBee.Rest; -public class TriggerInstanceAnalysisAdapter(IHttpClientFactory httpClientFactory) - : ITriggerInstanceAnalysis +public class TriggerInstanceAnalysisAdapter( + IHttpClientFactory httpClientFactory, + ILogger logger +) : ITriggerInstanceAnalysis { public async Task Trigger( InstanceInfo instanceInfo, @@ -18,27 +21,63 @@ public async Task Trigger( CancellationToken cancellationToken = default ) { - var client = httpClientFactory.CreateClient(); - client.BaseAddress = new Uri(instanceInfo.Url); + logger.LogDebug( + "Triggering analysis for script {ScriptId} on instance {InstanceId} at {InstanceUrl}", + scriptId, + instanceInfo.Id, + instanceInfo.Url + ); - var analysisApi = RestService.For(client); + try + { + var client = httpClientFactory.CreateClient(); + client.BaseAddress = new Uri(instanceInfo.Url); - var response = await analysisApi.Analyses( - new RunAnalysisCommand(instanceInfo.ProjectId.ToString(), scriptId.ToString()), - cancellationToken - ); + var analysisApi = RestService.For(client); - return new AnalysisInfo( - new AnalysisId(response.Id), - ProjectId.FromValue(response.ProjectId), - instanceInfo.Id, - new ScriptId(response.ScriptId), - null, - new AnalysisStatus(response.Status), - [], - [], - response.CreationDate, - null - ); + var response = await analysisApi.Analyses( + new RunAnalysisCommand(instanceInfo.ProjectId.ToString(), scriptId.ToString()), + cancellationToken + ); + + logger.LogDebug( + "Analysis {AnalysisId} triggered on instance {InstanceId}", + response.Id, + instanceInfo.Id + ); + + return new AnalysisInfo( + new AnalysisId(response.Id), + ProjectId.FromValue(response.ProjectId), + instanceInfo.Id, + new ScriptId(response.ScriptId), + null, + new AnalysisStatus(response.Status), + [], + [], + response.CreationDate, + null + ); + } + catch (Exception e) when (ExceptionUtils.IsConnectionRefused(e)) + { + logger.LogError( + e, + "Connection refused when triggering analysis on instance {InstanceId} at {InstanceUrl}", + instanceInfo.Id, + instanceInfo.Url + ); + throw; + } + catch (Exception e) + { + logger.LogError( + e, + "Failed to trigger analysis for script {ScriptId} on instance {InstanceId}", + scriptId, + instanceInfo.Id + ); + throw; + } } } diff --git a/ScriptBeeWebApp/src/Gateway/Adapters/Web/BackgroundServices/DeleteProjectLevelPluginsBackgroundService.cs b/ScriptBeeWebApp/src/Gateway/Adapters/Web/BackgroundServices/DeleteProjectLevelPluginsBackgroundService.cs index 9fcb39ff..ea50ee2b 100644 --- a/ScriptBeeWebApp/src/Gateway/Adapters/Web/BackgroundServices/DeleteProjectLevelPluginsBackgroundService.cs +++ b/ScriptBeeWebApp/src/Gateway/Adapters/Web/BackgroundServices/DeleteProjectLevelPluginsBackgroundService.cs @@ -12,12 +12,18 @@ ILogger logger { protected override async Task ExecuteAsync(CancellationToken stoppingToken) { + logger.LogInformation("Delete Project Plugins Background Service is starting"); + while (await eventChannel.Reader.WaitToReadAsync(stoppingToken)) { InstanceDeallocatedEvent? request = null; try { request = await eventChannel.Reader.ReadAsync(stoppingToken); + logger.LogDebug( + "Received instance-deallocated event for project {ProjectId}", + request.projectDetails.Id + ); await service.DeleteProjectPlugins(request.projectDetails, stoppingToken); } catch (Exception e) @@ -29,5 +35,7 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken) ); } } + + logger.LogInformation("Delete Project Plugins Background Service has stopped"); } } diff --git a/ScriptBeeWebApp/src/Gateway/Adapters/Web/BackgroundServices/InstallPluginsForAllocatedInstancesBackgroundService.cs b/ScriptBeeWebApp/src/Gateway/Adapters/Web/BackgroundServices/InstallPluginsForAllocatedInstancesBackgroundService.cs index cb9ed7a4..f861706d 100644 --- a/ScriptBeeWebApp/src/Gateway/Adapters/Web/BackgroundServices/InstallPluginsForAllocatedInstancesBackgroundService.cs +++ b/ScriptBeeWebApp/src/Gateway/Adapters/Web/BackgroundServices/InstallPluginsForAllocatedInstancesBackgroundService.cs @@ -12,12 +12,19 @@ ILogger logger { protected override async Task ExecuteAsync(CancellationToken stoppingToken) { + logger.LogInformation("Install Plugins Background Service is starting"); + while (await eventChannel.Reader.WaitToReadAsync(stoppingToken)) { InstanceAllocatedEvent? request = null; try { request = await eventChannel.Reader.ReadAsync(stoppingToken); + logger.LogDebug( + "Received instance-allocated event for project {ProjectId}, instance {InstanceId}", + request.projectDetails.Id, + request.instanceInfo.Id + ); await service.InstallPlugins( request.projectDetails, request.instanceInfo, @@ -33,5 +40,7 @@ await service.InstallPlugins( ); } } + + logger.LogInformation("Install Plugins Background Service has stopped"); } } diff --git a/ScriptBeeWebApp/src/Gateway/Adapters/Web/Program.cs b/ScriptBeeWebApp/src/Gateway/Adapters/Web/Program.cs index fb9e9725..372153a5 100644 --- a/ScriptBeeWebApp/src/Gateway/Adapters/Web/Program.cs +++ b/ScriptBeeWebApp/src/Gateway/Adapters/Web/Program.cs @@ -13,6 +13,7 @@ using ScriptBee.Web.EndpointDefinitions; using ScriptBee.Web.Extensions; using Serilog; +using Serilog.Events; var builder = WebApplication.CreateBuilder(args); @@ -86,7 +87,27 @@ app.MapHealthChecksEndpoint(); -app.UseSerilogRequestLogging(); +app.UseSerilogRequestLogging(options => +{ + options.GetLevel = (ctx, _, ex) => + ex is not null ? LogEventLevel.Error + : ctx.Request.Path.StartsWithSegments("/health") ? LogEventLevel.Debug + : LogEventLevel.Information; + + options.EnrichDiagnosticContext = (diagnosticContext, httpContext) => + { + diagnosticContext.Set("RequestHost", httpContext.Request.Host.Value); + diagnosticContext.Set("RequestScheme", httpContext.Request.Scheme); + if (httpContext.Request.Headers.TryGetValue("X-Client-Id", out var clientId)) + { + diagnosticContext.Set("ClientId", clientId.ToString()); + } + if (httpContext.User.Identity?.IsAuthenticated == true) + { + diagnosticContext.Set("UserName", httpContext.User.Identity.Name); + } + }; +}); app.UseExceptionEndpoint(); diff --git a/ScriptBeeWebApp/src/Gateway/Adapters/Web/appsettings.Development.json b/ScriptBeeWebApp/src/Gateway/Adapters/Web/appsettings.Development.json index e001e5dc..61924ae5 100644 --- a/ScriptBeeWebApp/src/Gateway/Adapters/Web/appsettings.Development.json +++ b/ScriptBeeWebApp/src/Gateway/Adapters/Web/appsettings.Development.json @@ -3,9 +3,9 @@ "MinimumLevel": { "Default": "Debug", "Override": { - "Microsoft": "Debug", - "System": "Debug", - "Microsoft.Hosting.Lifetime": "Debug" + "Microsoft": "Information", + "Microsoft.Hosting.Lifetime": "Information", + "Microsoft.AspNetCore": "Warning" } } }, diff --git a/ScriptBeeWebApp/src/Gateway/Adapters/Web/appsettings.json b/ScriptBeeWebApp/src/Gateway/Adapters/Web/appsettings.json index a019ae8f..1ed914b2 100644 --- a/ScriptBeeWebApp/src/Gateway/Adapters/Web/appsettings.json +++ b/ScriptBeeWebApp/src/Gateway/Adapters/Web/appsettings.json @@ -3,8 +3,7 @@ "MinimumLevel": { "Default": "Information", "Override": { - "Microsoft": "Information", - "System": "Information", + "Microsoft": "Warning", "Microsoft.Hosting.Lifetime": "Information" } }, diff --git a/ScriptBeeWebApp/src/Gateway/Application/Service.Gateway/Analysis/AnalysisStatusMonitorService.cs b/ScriptBeeWebApp/src/Gateway/Application/Service.Gateway/Analysis/AnalysisStatusMonitorService.cs index 65fa8d20..39918032 100644 --- a/ScriptBeeWebApp/src/Gateway/Application/Service.Gateway/Analysis/AnalysisStatusMonitorService.cs +++ b/ScriptBeeWebApp/src/Gateway/Application/Service.Gateway/Analysis/AnalysisStatusMonitorService.cs @@ -25,7 +25,14 @@ private readonly ConcurrentDictionary< public void Track(AnalysisId analysisId, ProjectId projectId) { - _trackedAnalyses.TryAdd(analysisId, (projectId, AnalysisStatus.Started.Value)); + if (_trackedAnalyses.TryAdd(analysisId, (projectId, AnalysisStatus.Started.Value))) + { + logger.LogInformation( + "Tracking analysis {AnalysisId} for project {ProjectId}", + analysisId, + projectId + ); + } } public async Task SeedRunningAnalyses(CancellationToken cancellationToken) diff --git a/ScriptBeeWebApp/src/Gateway/Application/Service.Gateway/Context/ClearInstanceContextService.cs b/ScriptBeeWebApp/src/Gateway/Application/Service.Gateway/Context/ClearInstanceContextService.cs index 39dbf9b3..00f6b5bf 100644 --- a/ScriptBeeWebApp/src/Gateway/Application/Service.Gateway/Context/ClearInstanceContextService.cs +++ b/ScriptBeeWebApp/src/Gateway/Application/Service.Gateway/Context/ClearInstanceContextService.cs @@ -1,4 +1,5 @@ -using OneOf; +using Microsoft.Extensions.Logging; +using OneOf; using OneOf.Types; using ScriptBee.Domain.Model.Errors; using ScriptBee.Ports.Instance; @@ -10,7 +11,8 @@ namespace ScriptBee.Service.Gateway.Context; public class ClearInstanceContextService( IGetProjectInstance getProjectInstance, - IClearInstanceContext clearInstanceContext + IClearInstanceContext clearInstanceContext, + ILogger logger ) : IClearInstanceContextUseCase { public async Task Clear( @@ -23,7 +25,12 @@ CancellationToken cancellationToken return await result.Match>( async instanceInfo => { + logger.LogInformation( + "Clearing context for instance {InstanceId}", + instanceInfo.Id + ); await clearInstanceContext.Clear(instanceInfo, cancellationToken); + logger.LogInformation("Context cleared for instance {InstanceId}", instanceInfo.Id); return new Success(); }, error => Task.FromResult(error) diff --git a/ScriptBeeWebApp/src/Gateway/Application/Service.Gateway/Context/LinkInstanceContextService.cs b/ScriptBeeWebApp/src/Gateway/Application/Service.Gateway/Context/LinkInstanceContextService.cs index e7b34276..f087710b 100644 --- a/ScriptBeeWebApp/src/Gateway/Application/Service.Gateway/Context/LinkInstanceContextService.cs +++ b/ScriptBeeWebApp/src/Gateway/Application/Service.Gateway/Context/LinkInstanceContextService.cs @@ -1,4 +1,5 @@ -using OneOf; +using Microsoft.Extensions.Logging; +using OneOf; using OneOf.Types; using ScriptBee.Domain.Model.Errors; using ScriptBee.Domain.Model.Instance; @@ -15,7 +16,8 @@ public class LinkInstanceContextService( IGetProject getProject, IGetProjectInstance getProjectInstance, ILinkInstanceContext linkInstanceContext, - IUpdateProject updateProject + IUpdateProject updateProject, + ILogger logger ) : ILinkInstanceContextUseCase { public async Task Link( @@ -63,8 +65,21 @@ private async Task Link( CancellationToken cancellationToken ) { + logger.LogInformation( + "Linking context for project {ProjectId} on instance {InstanceId} with linkers [{Linkers}]", + projectDetails.Id, + instanceInfo.Id, + string.Join(", ", linkerIds) + ); + await linkInstanceContext.Link(instanceInfo, linkerIds, cancellationToken); await updateProject.Update(projectDetails with { Linkers = linkerIds }, cancellationToken); + + logger.LogInformation( + "Context linked for project {ProjectId} on instance {InstanceId}", + projectDetails.Id, + instanceInfo.Id + ); } } diff --git a/ScriptBeeWebApp/src/Gateway/Application/Service.Gateway/Context/LoadInstanceContextService.cs b/ScriptBeeWebApp/src/Gateway/Application/Service.Gateway/Context/LoadInstanceContextService.cs index 2f479f83..c8514bd3 100644 --- a/ScriptBeeWebApp/src/Gateway/Application/Service.Gateway/Context/LoadInstanceContextService.cs +++ b/ScriptBeeWebApp/src/Gateway/Application/Service.Gateway/Context/LoadInstanceContextService.cs @@ -1,3 +1,4 @@ +using Microsoft.Extensions.Logging; using OneOf; using OneOf.Types; using ScriptBee.Domain.Model.Errors; @@ -16,7 +17,8 @@ public class LoadInstanceContextService( IGetProject getProject, IGetProjectInstance getProjectInstance, ILoadInstanceContext loadInstanceContext, - IUpdateProject updateProject + IUpdateProject updateProject, + ILogger logger ) : ILoadInstanceContextUseCase { public async Task Load( @@ -71,6 +73,15 @@ CancellationToken cancellationToken filesToLoad != null ? GetFilesToLoadFromFileIds(projectDetails.SavedFiles, filesToLoad) : GetFilesToLoadFromLoaderIds(projectDetails.SavedFiles, loaderIds ?? []); + + var loaderSummary = string.Join(", ", resolvedFilesToLoad.Keys); + logger.LogInformation( + "Loading context for project {ProjectId} on instance {InstanceId} with loaders [{Loaders}]", + projectDetails.Id, + instanceInfo.Id, + loaderSummary + ); + await loadInstanceContext.Load( instanceInfo, GetLoadedFileIds(resolvedFilesToLoad), @@ -80,6 +91,12 @@ await updateProject.Update( GetUpdateProjectDetailsWithLoadedFiles(projectDetails, resolvedFilesToLoad), cancellationToken ); + + logger.LogInformation( + "Context loaded for project {ProjectId} on instance {InstanceId}", + projectDetails.Id, + instanceInfo.Id + ); } private static Dictionary> GetFilesToLoadFromFileIds( diff --git a/ScriptBeeWebApp/src/Gateway/Application/Service.Gateway/Context/ReloadInstanceContextService.cs b/ScriptBeeWebApp/src/Gateway/Application/Service.Gateway/Context/ReloadInstanceContextService.cs index 529e9042..3ed74d28 100644 --- a/ScriptBeeWebApp/src/Gateway/Application/Service.Gateway/Context/ReloadInstanceContextService.cs +++ b/ScriptBeeWebApp/src/Gateway/Application/Service.Gateway/Context/ReloadInstanceContextService.cs @@ -1,4 +1,5 @@ -using OneOf; +using Microsoft.Extensions.Logging; +using OneOf; using OneOf.Types; using ScriptBee.Domain.Model.Errors; using ScriptBee.Domain.Model.Instance; @@ -16,7 +17,8 @@ public class ReloadInstanceContextService( IGetProjectInstance getProjectInstance, IClearInstanceContext clearInstanceContext, ILoadInstanceContext loadInstanceContext, - ILinkInstanceContext linkInstanceContext + ILinkInstanceContext linkInstanceContext, + ILogger logger ) : IReloadInstanceContextUseCase { public async Task Reload( @@ -57,6 +59,12 @@ private async Task ReloadContext( CancellationToken cancellationToken ) { + logger.LogInformation( + "Reloading context for project {ProjectId} on instance {InstanceId}", + projectDetails.Id, + instanceInfo.Id + ); + await clearInstanceContext.Clear(instanceInfo, cancellationToken); await loadInstanceContext.Load( instanceInfo, @@ -64,5 +72,11 @@ await loadInstanceContext.Load( cancellationToken ); await linkInstanceContext.Link(instanceInfo, projectDetails.Linkers, cancellationToken); + + logger.LogInformation( + "Context reloaded for project {ProjectId} on instance {InstanceId}", + projectDetails.Id, + instanceInfo.Id + ); } } diff --git a/ScriptBeeWebApp/src/Gateway/Application/Service.Gateway/CreateProjectService.cs b/ScriptBeeWebApp/src/Gateway/Application/Service.Gateway/CreateProjectService.cs index 00197e0f..45968100 100644 --- a/ScriptBeeWebApp/src/Gateway/Application/Service.Gateway/CreateProjectService.cs +++ b/ScriptBeeWebApp/src/Gateway/Application/Service.Gateway/CreateProjectService.cs @@ -1,4 +1,5 @@ -using OneOf; +using Microsoft.Extensions.Logging; +using OneOf; using ScriptBee.Common; using ScriptBee.Domain.Model.Errors; using ScriptBee.Domain.Model.File; @@ -14,7 +15,8 @@ public sealed class CreateProjectService( ICreateProject createProject, IDateTimeProvider dateTimeProvider, IGetDefaultCreatorRole getDefaultCreatorRole, - ISetResourceRole setResourceRole + ISetResourceRole setResourceRole, + ILogger logger ) : ICreateProjectUseCase { public async Task> CreateProject( @@ -22,6 +24,12 @@ public async Task> CreateProje CancellationToken cancellationToken ) { + logger.LogInformation( + "Creating project '{ProjectName}' with id '{ProjectId}'", + command.Name, + command.Id + ); + var projectDetails = new ProjectDetails( ProjectId.Create(command.Id), command.Name, @@ -37,6 +45,15 @@ CancellationToken cancellationToken if (result.IsT0) { await AssignDefaultRole(projectDetails.Id, command.UserId, cancellationToken); + logger.LogInformation( + "Project '{ProjectName}' ({ProjectId}) created successfully", + command.Name, + projectDetails.Id + ); + } + else + { + logger.LogWarning("Project id '{ProjectId}' is already in use", command.Id); } return result.Match>( diff --git a/ScriptBeeWebApp/src/Gateway/Application/Service.Gateway/DeleteProjectService.cs b/ScriptBeeWebApp/src/Gateway/Application/Service.Gateway/DeleteProjectService.cs index 10a626a0..4ef861c2 100644 --- a/ScriptBeeWebApp/src/Gateway/Application/Service.Gateway/DeleteProjectService.cs +++ b/ScriptBeeWebApp/src/Gateway/Application/Service.Gateway/DeleteProjectService.cs @@ -1,3 +1,4 @@ +using Microsoft.Extensions.Logging; using ScriptBee.Domain.Model.Project; using ScriptBee.Ports.Instance; using ScriptBee.Ports.Permissions; @@ -11,7 +12,8 @@ public sealed class DeleteProjectService( IDeleteProject deleteProject, IRemoveProjectMember removeProjectMember, IGetAllProjectInstances getAllProjectInstances, - IDeallocateProjectInstanceUseCase deallocateProjectInstance + IDeallocateProjectInstanceUseCase deallocateProjectInstance, + ILogger logger ) : IDeleteProjectUseCase { public async Task DeleteProject( @@ -21,9 +23,13 @@ public async Task DeleteProject( { var projectId = command.Id; + logger.LogInformation("Deleting project {ProjectId}", projectId); + await DeallocateAllInstances(projectId, cancellationToken); await removeProjectMember.RemoveAllProjectMembers(projectId, cancellationToken); await deleteProject.Delete(projectId, cancellationToken); + + logger.LogInformation("Project {ProjectId} deleted", projectId); } private async Task DeallocateAllInstances( @@ -40,6 +46,15 @@ CancellationToken cancellationToken .Cast() .ToList(); + if (tasks.Count > 0) + { + logger.LogInformation( + "Deallocating {InstanceCount} instance(s) for project {ProjectId}", + tasks.Count, + projectId + ); + } + await Task.WhenAll(tasks); } } diff --git a/ScriptBeeWebApp/src/Plugins/Plugins.Installer/BundlePluginInstaller.cs b/ScriptBeeWebApp/src/Plugins/Plugins.Installer/BundlePluginInstaller.cs index 47374e31..cdfeaf46 100644 --- a/ScriptBeeWebApp/src/Plugins/Plugins.Installer/BundlePluginInstaller.cs +++ b/ScriptBeeWebApp/src/Plugins/Plugins.Installer/BundlePluginInstaller.cs @@ -173,11 +173,15 @@ await installResult.Match( if (pluginIdsThatCouldNotBeInstalled.Count != 0) { - var errorMessage = pluginIdsThatCouldNotBeInstalled - .Select(id => $"Plugin {id.Name} version {id.Version} could not be installed.") - .Aggregate(string.Empty, (s, s1) => s + s1); - - logger.LogError("{Message}", errorMessage); + foreach (var failedId in pluginIdsThatCouldNotBeInstalled) + { + logger.LogError( + "Dependency plugin {PluginName} {PluginVersion} could not be installed for project {ProjectId}", + failedId.Name, + failedId.Version, + projectId + ); + } return new PluginInstallationError(pluginId, pluginIdsThatCouldNotBeInstalled); } @@ -256,11 +260,14 @@ CancellationToken cancellationToken if (pluginIdsThatCouldNotBeInstalled.Count != 0) { - var errorMessage = pluginIdsThatCouldNotBeInstalled - .Select(id => $"Plugin {id.Name} version {id.Version} could not be installed.") - .Aggregate(string.Empty, (s, s1) => s + s1); - - logger.LogError("{Message}", errorMessage); + foreach (var failedId in pluginIdsThatCouldNotBeInstalled) + { + logger.LogError( + "Dependency plugin {PluginName} {PluginVersion} could not be installed", + failedId.Name, + failedId.Version + ); + } return new PluginInstallationError(pluginId, pluginIdsThatCouldNotBeInstalled); } diff --git a/ScriptBeeWebApp/src/Plugins/Plugins.Installer/PluginUninstaller.cs b/ScriptBeeWebApp/src/Plugins/Plugins.Installer/PluginUninstaller.cs index 67a2d3f4..272f2d4c 100644 --- a/ScriptBeeWebApp/src/Plugins/Plugins.Installer/PluginUninstaller.cs +++ b/ScriptBeeWebApp/src/Plugins/Plugins.Installer/PluginUninstaller.cs @@ -7,8 +7,15 @@ public class PluginUninstaller(ILogger logger) : IPluginUnins { public void Uninstall(string pathToPlugin) { - logger.LogInformation("Uninstalling plugin: {PathToPlugin}", pathToPlugin); + var pluginName = Path.GetFileName(pathToPlugin); + logger.LogInformation( + "Uninstalling plugin {PluginName} from {PathToPlugin}", + pluginName, + pathToPlugin + ); new DirectoryInfo(pathToPlugin).DeleteIfExists(); + + logger.LogInformation("Plugin {PluginName} uninstalled", pluginName); } } diff --git a/ScriptBeeWebApp/src/Plugins/Plugins.Installer/PluginZipProcessor.cs b/ScriptBeeWebApp/src/Plugins/Plugins.Installer/PluginZipProcessor.cs index 6ccaadf4..435d21b1 100644 --- a/ScriptBeeWebApp/src/Plugins/Plugins.Installer/PluginZipProcessor.cs +++ b/ScriptBeeWebApp/src/Plugins/Plugins.Installer/PluginZipProcessor.cs @@ -42,16 +42,35 @@ public async Task< var finalPluginPath = GetProjectPluginFolderPath(projectId, plugin.Id); - if ( - Directory.Exists(finalPluginPath) - || Directory.Exists(GetGlobalPluginFolderPath(plugin.Id)) - ) + if (Directory.Exists(finalPluginPath)) { + logger.LogDebug( + "Plugin {PluginName} {PluginVersion} already exists at project path, skipping move", + plugin.Id.Name, + plugin.Id.Version + ); + return plugin.Id; + } + + if (Directory.Exists(GetGlobalPluginFolderPath(plugin.Id))) + { + logger.LogDebug( + "Plugin {PluginName} {PluginVersion} already exists at global path, skipping move", + plugin.Id.Name, + plugin.Id.Version + ); return plugin.Id; } Directory.Move(tempFolderPath, finalPluginPath); + logger.LogInformation( + "Plugin {PluginName} {PluginVersion} extracted from zip for project {ProjectId}", + plugin.Id.Name, + plugin.Id.Version, + projectId + ); + return plugin.Id; } catch (Exception e) diff --git a/ScriptBeeWebApp/test/Analysis/Adapters/Analysis.Web.Tests/BackgroundServices/RunScriptBackgroundServiceTest.cs b/ScriptBeeWebApp/test/Analysis/Adapters/Analysis.Web.Tests/BackgroundServices/RunScriptBackgroundServiceTest.cs index 20272707..db3e8d7a 100644 --- a/ScriptBeeWebApp/test/Analysis/Adapters/Analysis.Web.Tests/BackgroundServices/RunScriptBackgroundServiceTest.cs +++ b/ScriptBeeWebApp/test/Analysis/Adapters/Analysis.Web.Tests/BackgroundServices/RunScriptBackgroundServiceTest.cs @@ -1,5 +1,6 @@ using System.Threading.Channels; using DxWorks.ScriptBee.Plugin.Api; +using Microsoft.Extensions.Logging; using NSubstitute; using ScriptBee.Analysis.Web.BackgroundServices; using ScriptBee.Domain.Model.Analysis; @@ -19,7 +20,11 @@ public async Task ExecuteAsync_ShouldProcessRequestsFromChannel() { var runScriptChannel = Channel.CreateUnbounded(); var runScriptService = Substitute.For(); - var backgroundService = new RunScriptBackgroundService(runScriptChannel, runScriptService); + var backgroundService = new RunScriptBackgroundService( + runScriptChannel, + runScriptService, + new Logger(new LoggerFactory()) + ); var request1 = new RunScriptRequest( _scriptRunner, CreateScript(), diff --git a/ScriptBeeWebApp/test/Analysis/Application/Service.Analysis.Tests/InstallPluginServiceTest.cs b/ScriptBeeWebApp/test/Analysis/Application/Service.Analysis.Tests/InstallPluginServiceTest.cs index 8b886e39..dcab948b 100644 --- a/ScriptBeeWebApp/test/Analysis/Application/Service.Analysis.Tests/InstallPluginServiceTest.cs +++ b/ScriptBeeWebApp/test/Analysis/Application/Service.Analysis.Tests/InstallPluginServiceTest.cs @@ -1,3 +1,4 @@ +using Microsoft.Extensions.Logging; using NSubstitute; using NSubstitute.ExceptionExtensions; using OneOf.Types; @@ -29,7 +30,8 @@ public InstallPluginServiceTest() _projectManager, _pluginReader, _pluginLoader, - _pluginPathProvider + _pluginPathProvider, + new Logger(new LoggerFactory()) ); } diff --git a/ScriptBeeWebApp/test/Analysis/Application/Service.Analysis.Tests/LoadModelFilesServiceTest.cs b/ScriptBeeWebApp/test/Analysis/Application/Service.Analysis.Tests/LoadModelFilesServiceTest.cs index 4ffa564f..d6379c87 100644 --- a/ScriptBeeWebApp/test/Analysis/Application/Service.Analysis.Tests/LoadModelFilesServiceTest.cs +++ b/ScriptBeeWebApp/test/Analysis/Application/Service.Analysis.Tests/LoadModelFilesServiceTest.cs @@ -1,5 +1,6 @@ using DxWorks.ScriptBee.Plugin.Api; using DxWorks.ScriptBee.Plugin.Api.Model; +using Microsoft.Extensions.Logging; using NSubstitute; using ScriptBee.Artifacts; using ScriptBee.Domain.Model.File; @@ -23,7 +24,8 @@ public LoadModelFilesServiceTest() _loadModelFilesService = new LoadModelFilesService( _projectManager, _pluginRepository, - _fileModelService + _fileModelService, + new Logger(new LoggerFactory()) ); } diff --git a/ScriptBeeWebApp/test/Analysis/Application/Service.Analysis.Tests/RunAnalysisServiceTest.cs b/ScriptBeeWebApp/test/Analysis/Application/Service.Analysis.Tests/RunAnalysisServiceTest.cs index 10777198..869e1cfc 100644 --- a/ScriptBeeWebApp/test/Analysis/Application/Service.Analysis.Tests/RunAnalysisServiceTest.cs +++ b/ScriptBeeWebApp/test/Analysis/Application/Service.Analysis.Tests/RunAnalysisServiceTest.cs @@ -1,5 +1,6 @@ using System.Threading.Channels; using DxWorks.ScriptBee.Plugin.Api; +using Microsoft.Extensions.Logging; using NSubstitute; using OneOf; using ScriptBee.Artifacts; @@ -44,7 +45,8 @@ public RunAnalysisServiceTest() _getScripts, _pluginRepository, _runScriptChannel, - _instanceInformation + _instanceInformation, + new Logger(new LoggerFactory()) ); } diff --git a/ScriptBeeWebApp/test/Analysis/Application/Service.Analysis.Tests/RunScriptServiceTest.cs b/ScriptBeeWebApp/test/Analysis/Application/Service.Analysis.Tests/RunScriptServiceTest.cs index 2723ddc3..c2b17a1a 100644 --- a/ScriptBeeWebApp/test/Analysis/Application/Service.Analysis.Tests/RunScriptServiceTest.cs +++ b/ScriptBeeWebApp/test/Analysis/Application/Service.Analysis.Tests/RunScriptServiceTest.cs @@ -1,5 +1,6 @@ using DxWorks.ScriptBee.Plugin.Api; using DxWorks.ScriptBee.Plugin.Api.Model; +using Microsoft.Extensions.Logging; using NSubstitute; using NSubstitute.ExceptionExtensions; using OneOf; @@ -39,7 +40,8 @@ public RunScriptServiceTest() _dateTimeProvider, _guidProvider, _pluginRepository, - _projectManager + _projectManager, + new Logger(new LoggerFactory()) ); } diff --git a/ScriptBeeWebApp/test/Analysis/Application/Service.Analysis.Tests/Service.Analysis.Tests.csproj b/ScriptBeeWebApp/test/Analysis/Application/Service.Analysis.Tests/Service.Analysis.Tests.csproj index b483b5bc..4b631c07 100644 --- a/ScriptBeeWebApp/test/Analysis/Application/Service.Analysis.Tests/Service.Analysis.Tests.csproj +++ b/ScriptBeeWebApp/test/Analysis/Application/Service.Analysis.Tests/Service.Analysis.Tests.csproj @@ -4,5 +4,6 @@ + diff --git a/ScriptBeeWebApp/test/Gateway/Adapters/Rest.Tests/TriggerInstanceAnalysisAdapterTest.cs b/ScriptBeeWebApp/test/Gateway/Adapters/Rest.Tests/TriggerInstanceAnalysisAdapterTest.cs index 82a02af9..84253b76 100644 --- a/ScriptBeeWebApp/test/Gateway/Adapters/Rest.Tests/TriggerInstanceAnalysisAdapterTest.cs +++ b/ScriptBeeWebApp/test/Gateway/Adapters/Rest.Tests/TriggerInstanceAnalysisAdapterTest.cs @@ -1,3 +1,4 @@ +using Microsoft.Extensions.Logging; using ScriptBee.Domain.Model.Analysis; using ScriptBee.Domain.Model.Instance; using ScriptBee.Domain.Model.Project; @@ -13,7 +14,8 @@ public sealed class TriggerInstanceAnalysisAdapterTest : IDisposable private readonly WireMockServer _server = WireMockServer.Start(); private readonly TriggerInstanceAnalysisAdapter _triggerInstanceAnalysisAdapter = new( - new DefaultHttpClientFactory() + new DefaultHttpClientFactory(), + new Logger(new LoggerFactory()) ); public void Dispose() diff --git a/ScriptBeeWebApp/test/Gateway/Application/Service.Gateway.Tests/Context/ClearInstanceContextServiceTest.cs b/ScriptBeeWebApp/test/Gateway/Application/Service.Gateway.Tests/Context/ClearInstanceContextServiceTest.cs index f189d63d..59cf03e3 100644 --- a/ScriptBeeWebApp/test/Gateway/Application/Service.Gateway.Tests/Context/ClearInstanceContextServiceTest.cs +++ b/ScriptBeeWebApp/test/Gateway/Application/Service.Gateway.Tests/Context/ClearInstanceContextServiceTest.cs @@ -1,4 +1,5 @@ -using NSubstitute; +using Microsoft.Extensions.Logging; +using NSubstitute; using OneOf; using OneOf.Types; using ScriptBee.Domain.Model.Errors; @@ -25,7 +26,8 @@ public ClearInstanceContextServiceTest() { _clearInstanceContextService = new ClearInstanceContextService( _getProjectInstance, - _clearInstanceContext + _clearInstanceContext, + new Logger(new LoggerFactory()) ); } diff --git a/ScriptBeeWebApp/test/Gateway/Application/Service.Gateway.Tests/Context/LinkInstanceContextServiceTest.cs b/ScriptBeeWebApp/test/Gateway/Application/Service.Gateway.Tests/Context/LinkInstanceContextServiceTest.cs index 9c6c1fb5..54beeba1 100644 --- a/ScriptBeeWebApp/test/Gateway/Application/Service.Gateway.Tests/Context/LinkInstanceContextServiceTest.cs +++ b/ScriptBeeWebApp/test/Gateway/Application/Service.Gateway.Tests/Context/LinkInstanceContextServiceTest.cs @@ -1,4 +1,5 @@ -using NSubstitute; +using Microsoft.Extensions.Logging; +using NSubstitute; using OneOf; using OneOf.Types; using ScriptBee.Domain.Model.Errors; @@ -33,7 +34,8 @@ public LinkInstanceContextServiceTest() _getProject, _getProjectInstance, _linkInstanceContext, - _updateProject + _updateProject, + new Logger(new LoggerFactory()) ); } diff --git a/ScriptBeeWebApp/test/Gateway/Application/Service.Gateway.Tests/Context/LoadInstanceContextServiceTest.cs b/ScriptBeeWebApp/test/Gateway/Application/Service.Gateway.Tests/Context/LoadInstanceContextServiceTest.cs index be4de049..67fc6767 100644 --- a/ScriptBeeWebApp/test/Gateway/Application/Service.Gateway.Tests/Context/LoadInstanceContextServiceTest.cs +++ b/ScriptBeeWebApp/test/Gateway/Application/Service.Gateway.Tests/Context/LoadInstanceContextServiceTest.cs @@ -1,3 +1,4 @@ +using Microsoft.Extensions.Logging; using NSubstitute; using OneOf; using OneOf.Types; @@ -34,7 +35,8 @@ public LoadInstanceContextServiceTest() _getProject, _getProjectInstance, _loadInstanceContext, - _updateProject + _updateProject, + new Logger(new LoggerFactory()) ); } diff --git a/ScriptBeeWebApp/test/Gateway/Application/Service.Gateway.Tests/Context/ReloadInstanceContextServiceTest.cs b/ScriptBeeWebApp/test/Gateway/Application/Service.Gateway.Tests/Context/ReloadInstanceContextServiceTest.cs index 67411361..576a9ae9 100644 --- a/ScriptBeeWebApp/test/Gateway/Application/Service.Gateway.Tests/Context/ReloadInstanceContextServiceTest.cs +++ b/ScriptBeeWebApp/test/Gateway/Application/Service.Gateway.Tests/Context/ReloadInstanceContextServiceTest.cs @@ -1,3 +1,4 @@ +using Microsoft.Extensions.Logging; using NSubstitute; using OneOf; using OneOf.Types; @@ -39,7 +40,8 @@ public ReloadInstanceContextServiceTest() _getProjectInstance, _clearInstanceContext, _loadInstanceContext, - _linkInstanceContext + _linkInstanceContext, + new Logger(new LoggerFactory()) ); } diff --git a/ScriptBeeWebApp/test/Gateway/Application/Service.Gateway.Tests/CreateProjectServiceTests.cs b/ScriptBeeWebApp/test/Gateway/Application/Service.Gateway.Tests/CreateProjectServiceTests.cs index 617bc739..a10fa17e 100644 --- a/ScriptBeeWebApp/test/Gateway/Application/Service.Gateway.Tests/CreateProjectServiceTests.cs +++ b/ScriptBeeWebApp/test/Gateway/Application/Service.Gateway.Tests/CreateProjectServiceTests.cs @@ -1,4 +1,5 @@ -using NSubstitute; +using Microsoft.Extensions.Logging; +using NSubstitute; using OneOf; using OneOf.Types; using ScriptBee.Common; @@ -30,7 +31,8 @@ public CreateProjectServiceTests() _createProject, _dateTimeProvider, _getDefaultCreatorRole, - _setResourceRole + _setResourceRole, + new Logger(new LoggerFactory()) ); } diff --git a/ScriptBeeWebApp/test/Gateway/Application/Service.Gateway.Tests/DeleteProjectServiceTests.cs b/ScriptBeeWebApp/test/Gateway/Application/Service.Gateway.Tests/DeleteProjectServiceTests.cs index b70e5694..c4ec443d 100644 --- a/ScriptBeeWebApp/test/Gateway/Application/Service.Gateway.Tests/DeleteProjectServiceTests.cs +++ b/ScriptBeeWebApp/test/Gateway/Application/Service.Gateway.Tests/DeleteProjectServiceTests.cs @@ -1,3 +1,4 @@ +using Microsoft.Extensions.Logging; using NSubstitute; using NSubstitute.ExceptionExtensions; using OneOf; @@ -35,7 +36,8 @@ public DeleteProjectServiceTests() _deleteProject, _removeProjectMember, _getAllProjectInstances, - _deallocateProjectInstance + _deallocateProjectInstance, + new Logger(new LoggerFactory()) ); }