From 1e086258df550bb8deabcf32142d7c86b91780dc Mon Sep 17 00:00:00 2001 From: StuartFerguson Date: Sat, 12 Jul 2025 20:35:52 +0100 Subject: [PATCH] End to End correlation id --- ...ionProcessorACL.BusinessLogic.Tests.csproj | 6 ++-- ...ansactionProcessorACL.BusinessLogic.csproj | 6 ++-- ...actionProcessorACL.IntegrationTests.csproj | 14 ++++---- .../TransactionProcessorACL.Testing.csproj | 4 +-- .../TransactionProcessorACL.Tests.csproj | 6 ++-- TransactionProcessorACL/Program.cs | 34 ++++++++++++++++--- TransactionProcessorACL/Startup.cs | 34 +++++++------------ .../TransactionProcessorACL.csproj | 6 ++-- TransactionProcessorACL/nlog.config | 2 +- 9 files changed, 63 insertions(+), 49 deletions(-) diff --git a/TransactionProcessorACL.BusinessLogic.Tests/TransactionProcessorACL.BusinessLogic.Tests.csproj b/TransactionProcessorACL.BusinessLogic.Tests/TransactionProcessorACL.BusinessLogic.Tests.csproj index b478a52..210c25e 100644 --- a/TransactionProcessorACL.BusinessLogic.Tests/TransactionProcessorACL.BusinessLogic.Tests.csproj +++ b/TransactionProcessorACL.BusinessLogic.Tests/TransactionProcessorACL.BusinessLogic.Tests.csproj @@ -9,12 +9,12 @@ - + - - + + all diff --git a/TransactionProcessorACL.BusinessLogic/TransactionProcessorACL.BusinessLogic.csproj b/TransactionProcessorACL.BusinessLogic/TransactionProcessorACL.BusinessLogic.csproj index e57d447..930d104 100644 --- a/TransactionProcessorACL.BusinessLogic/TransactionProcessorACL.BusinessLogic.csproj +++ b/TransactionProcessorACL.BusinessLogic/TransactionProcessorACL.BusinessLogic.csproj @@ -6,9 +6,9 @@ - - - + + + diff --git a/TransactionProcessorACL.IntegrationTests/TransactionProcessorACL.IntegrationTests.csproj b/TransactionProcessorACL.IntegrationTests/TransactionProcessorACL.IntegrationTests.csproj index cc8bfc9..e6ac855 100644 --- a/TransactionProcessorACL.IntegrationTests/TransactionProcessorACL.IntegrationTests.csproj +++ b/TransactionProcessorACL.IntegrationTests/TransactionProcessorACL.IntegrationTests.csproj @@ -7,10 +7,10 @@ - + - + @@ -19,12 +19,12 @@ - - - + + + - - + + all diff --git a/TransactionProcessorACL.Testing/TransactionProcessorACL.Testing.csproj b/TransactionProcessorACL.Testing/TransactionProcessorACL.Testing.csproj index 052d3e2..1e4f414 100644 --- a/TransactionProcessorACL.Testing/TransactionProcessorACL.Testing.csproj +++ b/TransactionProcessorACL.Testing/TransactionProcessorACL.Testing.csproj @@ -6,8 +6,8 @@ - - + + diff --git a/TransactionProcessorACL.Tests/TransactionProcessorACL.Tests.csproj b/TransactionProcessorACL.Tests/TransactionProcessorACL.Tests.csproj index c00c7af..be5ed65 100644 --- a/TransactionProcessorACL.Tests/TransactionProcessorACL.Tests.csproj +++ b/TransactionProcessorACL.Tests/TransactionProcessorACL.Tests.csproj @@ -8,12 +8,12 @@ - + - - + + all diff --git a/TransactionProcessorACL/Program.cs b/TransactionProcessorACL/Program.cs index 7b858ff..70f196c 100644 --- a/TransactionProcessorACL/Program.cs +++ b/TransactionProcessorACL/Program.cs @@ -1,17 +1,21 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Shared.Logger; +using Shared.Middleware; namespace TransactionProcessorACL { + using Lamar.Microsoft.DependencyInjection; + using NLog; + using NLog.Extensions.Logging; using System.Diagnostics.CodeAnalysis; using System.IO; - using Lamar.Microsoft.DependencyInjection; [ExcludeFromCodeCoverage] public class Program @@ -31,9 +35,29 @@ public static IHostBuilder CreateHostBuilder(string[] args) .AddJsonFile("hosting.development.json", optional: true) .AddEnvironmentVariables().Build(); + String contentRoot = Directory.GetCurrentDirectory(); + String nlogConfigPath = Path.Combine(contentRoot, "nlog.config"); + + LogManager.Setup(b => + { + b.SetupLogFactory(setup => + { + setup.AddCallSiteHiddenAssembly(typeof(NlogLogger).Assembly); + setup.AddCallSiteHiddenAssembly(typeof(Shared.Logger.Logger).Assembly); + setup.AddCallSiteHiddenAssembly(typeof(TenantMiddleware).Assembly); + }); + b.LoadConfigurationFromFile(nlogConfigPath); + }); + + IHostBuilder hostBuilder = Host.CreateDefaultBuilder(args); hostBuilder.UseWindowsService(); hostBuilder.UseLamar(); + hostBuilder.ConfigureLogging(logging => { + logging.AddConsole(); + logging.AddNLog(); + + }); hostBuilder.ConfigureWebHostDefaults(webBuilder => { webBuilder.UseStartup(); diff --git a/TransactionProcessorACL/Startup.cs b/TransactionProcessorACL/Startup.cs index b0a04c9..d87249e 100644 --- a/TransactionProcessorACL/Startup.cs +++ b/TransactionProcessorACL/Startup.cs @@ -1,7 +1,3 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Mvc; @@ -9,13 +5,13 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; namespace TransactionProcessorACL { - using System.Diagnostics.CodeAnalysis; - using System.IO; - using System.Net.Http; - using System.Reflection; using Bootstrapper; using BusinessLogic.RequestHandlers; using BusinessLogic.Requests; @@ -41,8 +37,13 @@ namespace TransactionProcessorACL using Shared.Extensions; using Shared.General; using Shared.Logger; + using Shared.Middleware; using Swashbuckle.AspNetCore.Filters; using Swashbuckle.AspNetCore.SwaggerGen; + using System.Diagnostics.CodeAnalysis; + using System.IO; + using System.Net.Http; + using System.Reflection; using TransactionProcessor.Client; using ILogger = Microsoft.Extensions.Logging.ILogger; @@ -85,28 +86,17 @@ public void ConfigureContainer(ServiceRegistry services) // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerFactory loggerFactory) { - String nlogConfigFilename = "nlog.config"; - if (env.IsDevelopment()) - { - var developmentNlogConfigFilename = "nlog.development.config"; - if (File.Exists(Path.Combine(env.ContentRootPath, developmentNlogConfigFilename))) - { - nlogConfigFilename = developmentNlogConfigFilename; - } - + { app.UseDeveloperExceptionPage(); } - - loggerFactory.ConfigureNLog(Path.Combine(env.ContentRootPath, nlogConfigFilename)); - loggerFactory.AddNLog(); - + ILogger logger = loggerFactory.CreateLogger("TransactionProcessor"); Logger.Initialise(logger); Startup.Configuration.LogConfiguration(Logger.LogWarning); - + app.UseMiddleware(); app.AddRequestLogging(); app.AddResponseLogging(); app.AddExceptionHandler(); diff --git a/TransactionProcessorACL/TransactionProcessorACL.csproj b/TransactionProcessorACL/TransactionProcessorACL.csproj index 3e62715..ecc3fb3 100644 --- a/TransactionProcessorACL/TransactionProcessorACL.csproj +++ b/TransactionProcessorACL/TransactionProcessorACL.csproj @@ -18,7 +18,7 @@ - + @@ -26,8 +26,8 @@ - - + + diff --git a/TransactionProcessorACL/nlog.config b/TransactionProcessorACL/nlog.config index 9d844c4..f87bede 100644 --- a/TransactionProcessorACL/nlog.config +++ b/TransactionProcessorACL/nlog.config @@ -5,7 +5,7 @@