add-blazor-project #31

Merged
jleicher merged 5 commits from add-blazor-project into master 2020-12-29 21:04:02 +01:00
3 changed files with 34 additions and 1 deletions
Showing only changes of commit 44b257aaf7 - Show all commits

View File

@ -4,7 +4,8 @@
"Default": "Information", "Default": "Information",
"Microsoft": "Warning", "Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information", "Microsoft.Hosting.Lifetime": "Information",
"Microsoft.EntityFrameworkCore": "Information" "Microsoft.EntityFrameworkCore": "Information",
"HN.Application": "Information"
} }
} }
} }

View File

@ -0,0 +1,31 @@
using System;
using System.Threading;
using System.Threading.Tasks;
using MediatR;
using Microsoft.Extensions.Logging;
namespace HN.Infrastructure.Behaviors
{
public sealed class LoggerBehavior<TRequest, TResponse> : IPipelineBehavior<TRequest, TResponse>
{
private readonly ILoggerFactory _factory;
public LoggerBehavior(ILoggerFactory factory)
{
_factory = factory;
}
public async Task<TResponse> Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate<TResponse> next)
{
var logger = _factory.CreateLogger(request.GetType());
logger.LogInformation("Processing request {0} at {1}", request, DateTime.Now);
var response = await next();
logger.LogInformation("Processed request {0} at {1}", request, DateTime.Now);
return response;
}
}
}

View File

@ -33,6 +33,7 @@ namespace HN.Infrastructure
services.AddScoped<ILinkRepository, LinkRepository>(); services.AddScoped<ILinkRepository, LinkRepository>();
services.AddScoped<ICommentRepository, CommentRepository>(); services.AddScoped<ICommentRepository, CommentRepository>();
services.AddScoped(typeof(IPipelineBehavior<,>), typeof(UnitOfWorkBehavior<,>)); services.AddScoped(typeof(IPipelineBehavior<,>), typeof(UnitOfWorkBehavior<,>));
services.AddSingleton(typeof(IPipelineBehavior<,>), typeof(LoggerBehavior<,>));
services.AddMediatR(typeof(HN.Application.IHNContext)); services.AddMediatR(typeof(HN.Application.IHNContext));
return new HNServicesBuilder(services); return new HNServicesBuilder(services);