diff --git a/EstateReportingAPI.BusinessLogic/EstateReportingAPI.BusinessLogic.csproj b/EstateReportingAPI.BusinessLogic/EstateReportingAPI.BusinessLogic.csproj index 5c3b49a..0ff6dd5 100644 --- a/EstateReportingAPI.BusinessLogic/EstateReportingAPI.BusinessLogic.csproj +++ b/EstateReportingAPI.BusinessLogic/EstateReportingAPI.BusinessLogic.csproj @@ -8,8 +8,8 @@ - - + + diff --git a/EstateReportingAPI.BusinessLogic/ReportingManager.cs b/EstateReportingAPI.BusinessLogic/ReportingManager.cs index c7fc520..1bc0236 100644 --- a/EstateReportingAPI.BusinessLogic/ReportingManager.cs +++ b/EstateReportingAPI.BusinessLogic/ReportingManager.cs @@ -932,8 +932,7 @@ public async Task> GetOperators(Guid estateId, CancellationToken { Name = o.Name, EstateReportingId = context.Estates.Single(e => e.EstateId == o.EstateId).EstateReportingId, - OperatorId = o.OperatorId, - OperatorReportingId = o.OperatorReportingId + OperatorId = o.OperatorId }).ToListAsync(cancellationToken); return operators; diff --git a/EstateReportingAPI.Client/EstateReportingAPI.Client.csproj b/EstateReportingAPI.Client/EstateReportingAPI.Client.csproj index d2a9cb7..1e64f45 100644 --- a/EstateReportingAPI.Client/EstateReportingAPI.Client.csproj +++ b/EstateReportingAPI.Client/EstateReportingAPI.Client.csproj @@ -7,7 +7,7 @@ - + diff --git a/EstateReportingAPI.IntegrationTests/EstateReportingAPI.IntegrationTests.csproj b/EstateReportingAPI.IntegrationTests/EstateReportingAPI.IntegrationTests.csproj index abeff32..33cf80a 100644 --- a/EstateReportingAPI.IntegrationTests/EstateReportingAPI.IntegrationTests.csproj +++ b/EstateReportingAPI.IntegrationTests/EstateReportingAPI.IntegrationTests.csproj @@ -10,7 +10,7 @@ - + @@ -23,8 +23,8 @@ all - - + + diff --git a/EstateReportingAPI/Bootstrapper/MiddlewareRegistry.cs b/EstateReportingAPI/Bootstrapper/MiddlewareRegistry.cs index 027fe02..af645f1 100644 --- a/EstateReportingAPI/Bootstrapper/MiddlewareRegistry.cs +++ b/EstateReportingAPI/Bootstrapper/MiddlewareRegistry.cs @@ -1,4 +1,6 @@ -namespace EstateReportingAPI.Bootstrapper{ +using Shared.Middleware; + +namespace EstateReportingAPI.Bootstrapper{ using System.Diagnostics.CodeAnalysis; using System.Net.Security; using System.Reflection; @@ -88,6 +90,15 @@ public MiddlewareRegistry(){ Assembly assembly = this.GetType().GetTypeInfo().Assembly; this.AddMvcCore().AddApplicationPart(assembly).AddControllersAsServices(); + + bool logRequests = ConfigurationReaderExtensions.GetValueOrDefault("MiddlewareLogging", "LogRequests", true); + bool logResponses = ConfigurationReaderExtensions.GetValueOrDefault("MiddlewareLogging", "LogResponses", true); + LogLevel middlewareLogLevel = ConfigurationReaderExtensions.GetValueOrDefault("MiddlewareLogging", "MiddlewareLogLevel", LogLevel.Warning); + + RequestResponseMiddlewareLoggingConfig config = + new RequestResponseMiddlewareLoggingConfig(middlewareLogLevel, logRequests, logResponses); + + this.AddSingleton(config); } private HttpClientHandler ApiEndpointHttpHandler(IServiceProvider serviceProvider){ @@ -101,4 +112,26 @@ private HttpClientHandler ApiEndpointHttpHandler(IServiceProvider serviceProvide }; } } + + public static class ConfigurationReaderExtensions + { + public static T GetValueOrDefault(String sectionName, String keyName, T defaultValue) + { + try + { + var value = ConfigurationReader.GetValue(sectionName, keyName); + + if (String.IsNullOrEmpty(value)) + { + return defaultValue; + } + + return (T)Convert.ChangeType(value, typeof(T)); + } + catch (KeyNotFoundException kex) + { + return defaultValue; + } + } + } } \ No newline at end of file diff --git a/EstateReportingAPI/EstateReportingAPI.csproj b/EstateReportingAPI/EstateReportingAPI.csproj index 4e3ca1b..75ad1e5 100644 --- a/EstateReportingAPI/EstateReportingAPI.csproj +++ b/EstateReportingAPI/EstateReportingAPI.csproj @@ -9,7 +9,7 @@ - + @@ -19,7 +19,7 @@ - + diff --git a/EstateReportingAPI/Startup.cs b/EstateReportingAPI/Startup.cs index f48c4cd..3798ac1 100644 --- a/EstateReportingAPI/Startup.cs +++ b/EstateReportingAPI/Startup.cs @@ -63,6 +63,11 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerF if (env.IsDevelopment()) { + var developmentNlogConfigFilename = "nlog.development.config"; + if (File.Exists(Path.Combine(env.ContentRootPath, developmentNlogConfigFilename))) + { + nlogConfigFilename = developmentNlogConfigFilename; + } app.UseDeveloperExceptionPage(); } @@ -72,12 +77,7 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerF Microsoft.Extensions.Logging.ILogger logger = loggerFactory.CreateLogger("EstateManagement"); Logger.Initialise(logger); - - Action loggerAction = message => - { - Logger.LogInformation(message); - }; - Configuration.LogConfiguration(loggerAction); + Configuration.LogConfiguration(Logger.LogWarning); ConfigurationReader.Initialise(Configuration); diff --git a/EstateReportingAPI/nlog.config b/EstateReportingAPI/nlog.config index fbaf827..f400987 100644 --- a/EstateReportingAPI/nlog.config +++ b/EstateReportingAPI/nlog.config @@ -21,14 +21,23 @@ + + - - + + - +