diff --git a/Directory.Packages.props b/Directory.Packages.props index fdb0a74..a748d61 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -3,17 +3,17 @@ true - + - + - - + + @@ -21,17 +21,17 @@ - + - + - + @@ -40,8 +40,7 @@ - - + @@ -51,8 +50,8 @@ - - + + diff --git a/SecurityService.BusinessLogic/RequestHandlers/UserRequestHandler.cs b/SecurityService.BusinessLogic/RequestHandlers/UserRequestHandler.cs index 5bbd078..a56f08a 100644 --- a/SecurityService.BusinessLogic/RequestHandlers/UserRequestHandler.cs +++ b/SecurityService.BusinessLogic/RequestHandlers/UserRequestHandler.cs @@ -90,7 +90,7 @@ private async Task SendConfirmationEmail(ApplicationUser newIdentityUser SendEmailRequest emailRequest = this.BuildEmailConfirmationRequest(newIdentityUser, uri); Result sendEmailResult = await this.MessagingServiceClient.SendEmail(token.AccessToken, emailRequest, cancellationToken); if (sendEmailResult.IsFailed) { - Logger.LogWarning($"Error sending email to {newIdentityUser.Email} as part of user creation {sendEmailResult}"); + Logger.LogWarning("Error sending email to {emailaddress} as part of user creation {result}", newIdentityUser.Email, sendEmailResult); return ResultHelpers.CreateFailure(sendEmailResult); } diff --git a/SecurityService.IntegrationTests/Common/DockerHelper.cs b/SecurityService.IntegrationTests/Common/DockerHelper.cs index 5ca087b..d5f561f 100644 --- a/SecurityService.IntegrationTests/Common/DockerHelper.cs +++ b/SecurityService.IntegrationTests/Common/DockerHelper.cs @@ -9,6 +9,7 @@ namespace SecurityService.IntergrationTests.Common using NLog.Config; using SecurityService.IntegrationTesting.Helpers; using Shared.IntegrationTesting; + using Shared.IntegrationTesting.TestContainers; using System; using System.Collections.Generic; using System.Net; @@ -113,7 +114,8 @@ public override ContainerBuilder SetupSecurityServiceContainer() ContainerBuilder securityServiceContainer = new ContainerBuilder(imageDetailsResult.Data.imageName) .WithName(this.SecurityServiceContainerName) .WithEnvironment(environmentVariables) - .WithBindMount(this.IntegrationTestCertificate.CertificateDirectory, this.IntegrationTestCertificate.ContainerCertificateDirectory, AccessMode.ReadOnly); + .MountHostFolder(this.HostTraceFolder) + .WithResourceMapping(this.IntegrationTestCertificate.CertificateDirectory, this.IntegrationTestCertificate.ContainerCertificateDirectory); Int32? hostPort = this.GetHostPort(ContainerType.SecurityService); if (hostPort is null || hostPort <= 0) diff --git a/SecurityService.IntegrationTests/Common/GenericSteps.cs b/SecurityService.IntegrationTests/Common/GenericSteps.cs index bc10bf1..5e1b40b 100644 --- a/SecurityService.IntegrationTests/Common/GenericSteps.cs +++ b/SecurityService.IntegrationTests/Common/GenericSteps.cs @@ -36,11 +36,12 @@ public GenericSteps(ScenarioContext scenarioContext, public async Task StartSystem() { // Initialise a logger - String scenarioName = this.ScenarioContext.ScenarioInfo.Title.Replace(" ", ""); - NlogLogger logger = new NlogLogger(); + String scenarioName = this.ScenarioContext.ScenarioInfo.Title.Replace(" ", String.Empty); + NlogLogger logger = new(); logger.Initialise(LogManager.GetLogger(scenarioName), scenarioName); - LogManager.AddHiddenAssembly(typeof(NlogLogger).Assembly); - + LogManager.Setup().SetupLogFactory(setup => + setup.AddCallSiteHiddenAssembly(typeof(NlogLogger).Assembly)); + DockerServices dockerServices = DockerServices.SecurityService | DockerServices.SqlServer; this.TestingContext.DockerHelper = new DockerHelper(); diff --git a/SecurityService.OpenIdConnect.IntegrationTests/Common/DockerHelper.cs b/SecurityService.OpenIdConnect.IntegrationTests/Common/DockerHelper.cs index db77680..8f3d446 100644 --- a/SecurityService.OpenIdConnect.IntegrationTests/Common/DockerHelper.cs +++ b/SecurityService.OpenIdConnect.IntegrationTests/Common/DockerHelper.cs @@ -297,7 +297,7 @@ public override ContainerBuilder SetupSecurityServiceContainer() .WithName(this.SecurityServiceContainerName) .WithEnvironment(environmentVariables) .WithPortBinding(DockerPorts.SecurityServiceDockerPort, DockerPorts.SecurityServiceDockerPort) - .WithBindMount(this.IntegrationTestCertificate.CertificateDirectory, this.IntegrationTestCertificate.ContainerCertificateDirectory, AccessMode.ReadOnly) + .WithResourceMapping(this.IntegrationTestCertificate.CertificateDirectory, this.IntegrationTestCertificate.ContainerCertificateDirectory) .MountHostFolder(this.HostTraceFolder); return securityServiceContainer; diff --git a/SecurityService.OpenIdConnect.IntegrationTests/Common/GenericSteps.cs b/SecurityService.OpenIdConnect.IntegrationTests/Common/GenericSteps.cs index f432a02..4b5a4df 100644 --- a/SecurityService.OpenIdConnect.IntegrationTests/Common/GenericSteps.cs +++ b/SecurityService.OpenIdConnect.IntegrationTests/Common/GenericSteps.cs @@ -31,9 +31,10 @@ public async Task StartSystem() { // Initialise a logger String scenarioName = this.ScenarioContext.ScenarioInfo.Title.Replace(" ", String.Empty); - NlogLogger logger = new NlogLogger(); + NlogLogger logger = new(); logger.Initialise(LogManager.GetLogger(scenarioName), scenarioName); - LogManager.AddHiddenAssembly(typeof(NlogLogger).Assembly); + LogManager.Setup().SetupLogFactory(setup => + setup.AddCallSiteHiddenAssembly(typeof(NlogLogger).Assembly)); DockerServices dockerServices = DockerServices.SecurityService | DockerServices.SqlServer | DockerServices.MessagingService | DockerServices.KurrentDb; diff --git a/SecurityService/HostedServices/DatabaseInitializer.cs b/SecurityService/HostedServices/DatabaseInitializer.cs index 85e8048..8c95651 100644 --- a/SecurityService/HostedServices/DatabaseInitializer.cs +++ b/SecurityService/HostedServices/DatabaseInitializer.cs @@ -30,7 +30,7 @@ public async Task StartAsync(CancellationToken cancellationToken) SecurityServiceDbContext dbContext = scope.ServiceProvider.GetRequiredService(); if (this.Options.UseInMemoryDatabase) { - Logger.LogInformation($"Using in-memory database '{this.Options.InMemoryDatabaseName}'."); + Logger.LogInformation("Using in-memory database '{databaseName}'.", this.Options.InMemoryDatabaseName); await dbContext.Database.EnsureCreatedAsync(cancellationToken); } else { @@ -47,7 +47,7 @@ public async Task StartAsync(CancellationToken cancellationToken) foreach ((string name, string displayName, string description) in defaultScopes) { if (await scopeManager.FindByNameAsync(name, cancellationToken) is null) { - Logger.LogInformation($"Creating default scope {name}."); + Logger.LogInformation("Creating default scope {scopeName}.", name); await scopeManager.CreateAsync(new OpenIddictScopeDescriptor { Name = name, DisplayName = displayName, Description = description }, cancellationToken); } } @@ -61,7 +61,7 @@ public async Task StartAsync(CancellationToken cancellationToken) Logger.LogWarning("Database initialization complete."); } catch (Exception ex) { - Logger.LogError(new Exception("An error occurred during database initialization.", ex)); + Logger.LogError(ex, "An error occurred during database initialization."); throw; } } diff --git a/SecurityService/OpenApi/DtoXmlSchemaTransformer.cs b/SecurityService/OpenApi/DtoXmlSchemaTransformer.cs index 1ec3968..9a19b1b 100644 --- a/SecurityService/OpenApi/DtoXmlSchemaTransformer.cs +++ b/SecurityService/OpenApi/DtoXmlSchemaTransformer.cs @@ -1,7 +1,8 @@ -using System.Reflection; -using System.Xml; using Microsoft.AspNetCore.OpenApi; using Microsoft.OpenApi; +using System.Reflection; +using System.Text.Json.Nodes; +using System.Xml; namespace SecurityService.OpenApi; @@ -58,7 +59,7 @@ private static void ApplyExample(OpenApiSchema schema, XmlNode member) { try { - schema.Example = System.Text.Json.Nodes.JsonNode.Parse(example); + schema.Examples = [JsonNode.Parse(example)!]; } catch (System.Text.Json.JsonException) { diff --git a/SecurityService/OpenApi/OidcRequestDocumentationTransformer.cs b/SecurityService/OpenApi/OidcRequestDocumentationTransformer.cs index eb96f6b..6c8a20f 100644 --- a/SecurityService/OpenApi/OidcRequestDocumentationTransformer.cs +++ b/SecurityService/OpenApi/OidcRequestDocumentationTransformer.cs @@ -107,7 +107,7 @@ private static void AddParameter(OpenApiOperation operation, string name, string In = ParameterLocation.Query, Description = description, Required = required, - Schema = new OpenApiSchema { Type = JsonSchemaType.String, Example = JsonValue.Create(value) }, + Schema = new OpenApiSchema { Type = JsonSchemaType.String, Examples = [JsonValue.Create(value)] }, Example = JsonValue.Create(value) }); } diff --git a/SecurityService/Program.cs b/SecurityService/Program.cs index c50806a..0b63678 100644 --- a/SecurityService/Program.cs +++ b/SecurityService/Program.cs @@ -379,14 +379,12 @@ var app = builder.Build(); -if (builder.Environment.IsDevelopment()) -{ +if (builder.Environment.IsDevelopment()) { app.UseDeveloperExceptionPage(); } -ILogger logger = builder.Services.BuildServiceProvider().GetRequiredService().CreateLogger("Security Service"); - -Logger.Initialise(logger); +NLog.Logger logger = LogManager.GetLogger("Security Service"); +Shared.Logger.Logger.Initialise(logger, "securityservice"); builder.Configuration.LogConfiguration(Logger.LogWarning); app.UseMiddleware(); app.AddRequestResponseLogging(); diff --git a/SecurityService/nlog.config b/SecurityService/nlog.config index 1e7940b..9a5564b 100644 --- a/SecurityService/nlog.config +++ b/SecurityService/nlog.config @@ -3,27 +3,23 @@ - - - - + + + + + + + + +