Skip to content

Commit 6d622dc

Browse files
trace improvements
1 parent db2676f commit 6d622dc

8 files changed

Lines changed: 61 additions & 20 deletions

File tree

EstateReportingAPI.BusinessLogic/EstateReportingAPI.BusinessLogic.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88

99
<ItemGroup>
1010
<PackageReference Include="Microsoft.EntityFrameworkCore.DynamicLinq" Version="8.3.10" />
11-
<PackageReference Include="Shared" Version="2024.5.1" />
12-
<PackageReference Include="EstateManagement.Database" Version="2024.6.3" />
11+
<PackageReference Include="Shared" Version="2024.7.1" />
12+
<PackageReference Include="EstateManagement.Database" Version="2024.6.5" />
1313
</ItemGroup>
1414

1515
<ItemGroup>

EstateReportingAPI.BusinessLogic/ReportingManager.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -932,8 +932,7 @@ public async Task<List<Operator>> GetOperators(Guid estateId, CancellationToken
932932
{
933933
Name = o.Name,
934934
EstateReportingId = context.Estates.Single(e => e.EstateId == o.EstateId).EstateReportingId,
935-
OperatorId = o.OperatorId,
936-
OperatorReportingId = o.OperatorReportingId
935+
OperatorId = o.OperatorId
937936
}).ToListAsync(cancellationToken);
938937

939938
return operators;

EstateReportingAPI.Client/EstateReportingAPI.Client.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
</PropertyGroup>
88

99
<ItemGroup>
10-
<PackageReference Include="ClientProxyBase" Version="2024.5.1" />
10+
<PackageReference Include="ClientProxyBase" Version="2024.7.1" />
1111
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
1212
</ItemGroup>
1313

EstateReportingAPI.IntegrationTests/EstateReportingAPI.IntegrationTests.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
</PropertyGroup>
1111

1212
<ItemGroup>
13-
<PackageReference Include="EstateManagement.Database" Version="2024.6.3" />
13+
<PackageReference Include="EstateManagement.Database" Version="2024.6.5" />
1414
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="8.0.3" />
1515
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
1616
<PackageReference Include="xunit" Version="2.7.0" />
@@ -23,8 +23,8 @@
2323
<PrivateAssets>all</PrivateAssets>
2424
</PackageReference>
2525
<PackageReference Include="Shouldly" Version="4.2.1" />
26-
<PackageReference Include="Shared" Version="2024.5.1" />
27-
<PackageReference Include="Shared.IntegrationTesting" Version="2024.5.1" />
26+
<PackageReference Include="Shared" Version="2024.7.1" />
27+
<PackageReference Include="Shared.IntegrationTesting" Version="2024.7.1" />
2828
<PackageReference Include="Ductus.FluentDocker" Version="2.10.59" />
2929
<PackageReference Include="NLog" Version="5.2.8" />
3030
<PackageReference Include="NLog.Extensions.Logging" Version="5.3.8" />

EstateReportingAPI/Bootstrapper/MiddlewareRegistry.cs

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
namespace EstateReportingAPI.Bootstrapper{
1+
using Shared.Middleware;
2+
3+
namespace EstateReportingAPI.Bootstrapper{
24
using System.Diagnostics.CodeAnalysis;
35
using System.Net.Security;
46
using System.Reflection;
@@ -88,6 +90,15 @@ public MiddlewareRegistry(){
8890

8991
Assembly assembly = this.GetType().GetTypeInfo().Assembly;
9092
this.AddMvcCore().AddApplicationPart(assembly).AddControllersAsServices();
93+
94+
bool logRequests = ConfigurationReaderExtensions.GetValueOrDefault<Boolean>("MiddlewareLogging", "LogRequests", true);
95+
bool logResponses = ConfigurationReaderExtensions.GetValueOrDefault<Boolean>("MiddlewareLogging", "LogResponses", true);
96+
LogLevel middlewareLogLevel = ConfigurationReaderExtensions.GetValueOrDefault<LogLevel>("MiddlewareLogging", "MiddlewareLogLevel", LogLevel.Warning);
97+
98+
RequestResponseMiddlewareLoggingConfig config =
99+
new RequestResponseMiddlewareLoggingConfig(middlewareLogLevel, logRequests, logResponses);
100+
101+
this.AddSingleton(config);
91102
}
92103

93104
private HttpClientHandler ApiEndpointHttpHandler(IServiceProvider serviceProvider){
@@ -101,4 +112,26 @@ private HttpClientHandler ApiEndpointHttpHandler(IServiceProvider serviceProvide
101112
};
102113
}
103114
}
115+
116+
public static class ConfigurationReaderExtensions
117+
{
118+
public static T GetValueOrDefault<T>(String sectionName, String keyName, T defaultValue)
119+
{
120+
try
121+
{
122+
var value = ConfigurationReader.GetValue(sectionName, keyName);
123+
124+
if (String.IsNullOrEmpty(value))
125+
{
126+
return defaultValue;
127+
}
128+
129+
return (T)Convert.ChangeType(value, typeof(T));
130+
}
131+
catch (KeyNotFoundException kex)
132+
{
133+
return defaultValue;
134+
}
135+
}
136+
}
104137
}

EstateReportingAPI/EstateReportingAPI.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
</PropertyGroup>
1010

1111
<ItemGroup>
12-
<PackageReference Include="EstateManagement.Database" Version="2024.6.3" />
12+
<PackageReference Include="EstateManagement.Database" Version="2024.6.5" />
1313
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="8.0.3" />
1414
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.20.0" />
1515
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
@@ -19,7 +19,7 @@
1919
<PackageReference Include="Lamar" Version="13.0.3" />
2020
<PackageReference Include="Lamar.Microsoft.DependencyInjection" Version="13.0.3" />
2121
<PackageReference Include="NLog.Extensions.Logging" Version="5.3.8" />
22-
<PackageReference Include="Shared" Version="2024.5.1" />
22+
<PackageReference Include="Shared" Version="2024.7.1" />
2323
<PackageReference Include="AspNetCore.HealthChecks.SqlServer" Version="8.0.0" />
2424
<PackageReference Include="AspNetCore.HealthChecks.UI" Version="8.0.0" />
2525
<PackageReference Include="AspNetCore.HealthChecks.UI.Client" Version="8.0.0" />

EstateReportingAPI/Startup.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerF
6363

6464
if (env.IsDevelopment())
6565
{
66+
var developmentNlogConfigFilename = "nlog.development.config";
67+
if (File.Exists(Path.Combine(env.ContentRootPath, developmentNlogConfigFilename)))
68+
{
69+
nlogConfigFilename = developmentNlogConfigFilename;
70+
}
6671
app.UseDeveloperExceptionPage();
6772
}
6873

@@ -72,12 +77,7 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerF
7277
Microsoft.Extensions.Logging.ILogger logger = loggerFactory.CreateLogger("EstateManagement");
7378

7479
Logger.Initialise(logger);
75-
76-
Action<string> loggerAction = message =>
77-
{
78-
Logger.LogInformation(message);
79-
};
80-
Configuration.LogConfiguration(loggerAction);
80+
Configuration.LogConfiguration(Logger.LogWarning);
8181

8282
ConfigurationReader.Initialise(Configuration);
8383

EstateReportingAPI/nlog.config

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,23 @@
2121
</target>
2222
</targets>
2323

24+
<!--
25+
Trace - Very detailed log messages, potentially of a high frequency and volume
26+
Debug -Less detailed and/or less frequent debugging messages
27+
Info - Informational messages
28+
Warn - Warnings which don't appear to the user of the application
29+
Error - Error messages
30+
Fatal - Fatal error messages. After a fatal error, the application usually terminates
31+
-->
32+
2433
<rules>
25-
<logger name="Microsoft.*" minlevel="Debug" writeTo="" final="true" />
26-
<logger name="*" minlevel="Debug" writeTo="logfile">
34+
<logger name="Microsoft.*" minlevel="Warn" writeTo="" final="true" />
35+
<logger name="*" minlevel="Warn" writeTo="logfile">
2736
<filters defaultAction="Log">
2837
<when condition="contains('${message}', 'HEALTH_CHECK')" action="Ignore"></when>
2938
</filters>
3039
</logger>
31-
<logger name="*" minlevel="Debug" writeTo="healthlogfile">
40+
<logger name="*" minlevel="Warn" writeTo="healthlogfile">
3241
<filters defaultAction="Ignore">
3342
<when condition="contains('${message}', 'HEALTH_CHECK')" action="Log"></when>
3443
</filters>

0 commit comments

Comments
 (0)