Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageReference Include="Moq" Version="4.20.70" />
<PackageReference Include="Shared.EventStore" Version="2024.4.1" />
<PackageReference Include="Shared.EventStore" Version="2024.7.1" />
<PackageReference Include="Shouldly" Version="4.2.1" />
<PackageReference Include="xunit" Version="2.7.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.7">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="MediatR" Version="12.2.0" />
<PackageReference Include="Shared" Version="2024.4.1" />
<PackageReference Include="Shared.DomainDrivenDesign" Version="2024.4.1" />
<PackageReference Include="Shared.EventStore" Version="2024.4.1" />
<PackageReference Include="Shared" Version="2024.7.1" />
<PackageReference Include="Shared.DomainDrivenDesign" Version="2024.7.1" />
<PackageReference Include="Shared.EventStore" Version="2024.7.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\CallbackHandler.CallbackMessageAggregate\CallbackHandler.CallbackMessageAggregate.csproj" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Shared" Version="2024.4.1" />
<PackageReference Include="Shared.DomainDrivenDesign" Version="2024.4.1" />
<PackageReference Include="Shared" Version="2024.7.1" />
<PackageReference Include="Shared.DomainDrivenDesign" Version="2024.7.1" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageReference Include="Shared.EventStore" Version="2024.4.1" />
<PackageReference Include="Shared.EventStore" Version="2024.7.1" />
<PackageReference Include="Shouldly" Version="4.2.1" />
<PackageReference Include="xunit" Version="2.7.0" />
<PackageReference Include="xunit.extensibility.core" Version="2.7.0" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Grpc.Net.Client" Version="2.61.0" />
<PackageReference Include="Shared" Version="2024.4.1" />
<PackageReference Include="Shared.DomainDrivenDesign" Version="2024.4.1" />
<PackageReference Include="Shared.EventStore" Version="2024.4.1" />
<PackageReference Include="Shared" Version="2024.7.1" />
<PackageReference Include="Shared.DomainDrivenDesign" Version="2024.7.1" />
<PackageReference Include="Shared.EventStore" Version="2024.7.1" />
</ItemGroup>
</Project>
38 changes: 37 additions & 1 deletion CallbackHandler/Bootstrapper/MiddlewareRegistry.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
namespace CallbackHandler.Bootstrapper
using Microsoft.Extensions.Logging;

namespace CallbackHandler.Bootstrapper
{
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Reflection;
Expand All @@ -14,6 +17,8 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
using Shared.EventStore.Extensions;
using Shared.General;
using Shared.Middleware;
using Swashbuckle.AspNetCore.Filters;

[ExcludeFromCodeCoverage]
Expand Down Expand Up @@ -71,6 +76,37 @@ public MiddlewareRegistry()

Assembly assembly = this.GetType().GetTypeInfo().Assembly;
this.AddMvcCore().AddApplicationPart(assembly).AddControllersAsServices();

bool logRequests = ConfigurationReaderExtensions.GetValueOrDefault<Boolean>("MiddlewareLogging", "LogRequests", true);
bool logResponses = ConfigurationReaderExtensions.GetValueOrDefault<Boolean>("MiddlewareLogging", "LogResponses", true);
LogLevel middlewareLogLevel = ConfigurationReaderExtensions.GetValueOrDefault<LogLevel>("MiddlewareLogging", "MiddlewareLogLevel", LogLevel.Warning);

RequestResponseMiddlewareLoggingConfig config =
new RequestResponseMiddlewareLoggingConfig(middlewareLogLevel, logRequests, logResponses);

this.AddSingleton(config);
}
}

public static class ConfigurationReaderExtensions
{
public static T GetValueOrDefault<T>(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;
}
}
}
}
2 changes: 2 additions & 0 deletions CallbackHandler/Bootstrapper/RepositoryRegistry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,7 @@ public RepositoryRegistry()
this.AddEventStorePersistentSubscriptionsClient(connectionString);

this.AddEventStoreClient(connectionString);

this.AddSingleton<IDomainEventFactory<IDomainEvent>, DomainEventFactory>();
}
}
2 changes: 1 addition & 1 deletion CallbackHandler/CallbackHandler.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<PackageReference Include="AspNetCore.HealthChecks.UI.Client" Version="8.0.0" />
<PackageReference Include="MediatR" Version="12.2.0" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.19.6" />
<PackageReference Include="Shared" Version="2024.4.1" />
<PackageReference Include="Shared" Version="2024.7.1" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
<PackageReference Include="Swashbuckle.AspNetCore.Annotations" Version="6.5.0" />
<PackageReference Include="Swashbuckle.AspNetCore.Filters" Version="8.0.1" />
Expand Down
13 changes: 6 additions & 7 deletions CallbackHandler/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,11 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerF

if (env.IsDevelopment())
{
nlogConfigFilename = $"nlog.{env.EnvironmentName}.config";
var developmentNlogConfigFilename = "nlog.development.config";
if (File.Exists(Path.Combine(env.ContentRootPath, developmentNlogConfigFilename)))
{
nlogConfigFilename = developmentNlogConfigFilename;
}
app.UseDeveloperExceptionPage();
}

Expand All @@ -106,12 +110,7 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerF
ILogger logger = loggerFactory.CreateLogger("CallbackHandler");

Logger.Initialise(logger);

Action<String> loggerAction = message =>
{
Logger.LogInformation(message);
};
Startup.Configuration.LogConfiguration(loggerAction);
Startup.Configuration.LogConfiguration(Logger.LogWarning);

ConfigurationReader.Initialise(Startup.Configuration);

Expand Down
19 changes: 14 additions & 5 deletions CallbackHandler/nlog.config
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,24 @@

</target>
</targets>

<rules>
<logger name="Microsoft.*" minlevel="Debug" writeTo="" final="true" />
<logger name="*" minlevel="Debug" writeTo="logfile">

<!--
Trace - Very detailed log messages, potentially of a high frequency and volume
Debug -Less detailed and/or less frequent debugging messages
Info - Informational messages
Warn - Warnings which don't appear to the user of the application
Error - Error messages
Fatal - Fatal error messages. After a fatal error, the application usually terminates
-->

<rules>
<logger name="Microsoft.*" minlevel="Warn" writeTo="" final="true" />
<logger name="*" minlevel="Warn" writeTo="logfile">
<filters defaultAction="Log">
<when condition="contains('${message}', 'HEALTH_CHECK')" action="Ignore"></when>
</filters>
</logger>
<logger name="*" minlevel="Debug" writeTo="healthlogfile">
<logger name="*" minlevel="Warn" writeTo="healthlogfile">
<filters defaultAction="Ignore">
<when condition="contains('${message}', 'HEALTH_CHECK')" action="Log"></when>
</filters>
Expand Down