This commit is contained in:
john 2025-05-16 16:10:01 +02:00
parent 14fd359ea8
commit a4ef2b4a20
26 changed files with 331 additions and 78 deletions

View file

@ -9,6 +9,7 @@
<ItemGroup>
<PackageReference Include="MediatR" Version="12.5.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="9.0.4" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="9.0.4" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="9.0.4" />
<PackageReference Include="Npgsql" Version="9.0.3" />
<PackageReference Include="Quartz" Version="3.14.0" />

View file

@ -0,0 +1,19 @@
using MediatR;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
namespace Femto.Common.Infrastructure;
public static class DomainServiceExtensions
{
public static void ConfigureDomainServices<TContext>(this IServiceCollection services)
where TContext : DbContext
{
services.AddScoped<DbContext>(s => s.GetRequiredService<TContext>());
services.AddTransient(
typeof(IPipelineBehavior<,>),
typeof(SaveChangesPipelineBehaviour<,>)
);
}
}

View file

@ -0,0 +1,37 @@
using Microsoft.Extensions.Logging;
namespace Femto.Common.Logs;
public static partial class LoggerExtensions
{
[LoggerMessage(
LogLevel.Error,
EventId = 1,
EventName = "FailedRequestWithException",
Message = "Request failed: {Method} {Path}, Status: {StatusCode}, TraceId: {TraceId}, Message: {Message}"
)]
public static partial void LogFailedRequest(
this ILogger logger,
Exception exception,
string method,
string path,
int statusCode,
string traceId,
string message
);
[LoggerMessage(
LogLevel.Error,
EventId = 2,
EventName = "FailedRequest",
Message = "Request failed: {Method} {Path}, Status: {StatusCode}, TraceId: {TraceId}, Message: {Message}"
)]
public static partial void LogFailedRequest(
this ILogger logger,
string method,
string path,
int statusCode,
string traceId,
string message
);
}