添加serilog日志支持和部分其他efcore代码

This commit is contained in:
2021-02-23 16:16:03 +08:00
parent 0f98c15cd4
commit d639db3574
19 changed files with 506 additions and 28 deletions

View File

@@ -0,0 +1,24 @@
using MediatR;
using Microsoft.Extensions.Logging;
using QRCodeService.Extensions;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
namespace QRCodeService.Application.Behaviors
{
public class LoggingBehavior<TRequest, TResponse> : IPipelineBehavior<TRequest, TResponse>
{
private readonly ILogger<LoggingBehavior<TRequest, TResponse>> _logger;
public LoggingBehavior(ILogger<LoggingBehavior<TRequest, TResponse>> logger) => _logger = logger;
public async Task<TResponse> Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate<TResponse> next)
{
_logger.LogInformation("----- Handling command {CommandName} ({@Command})", request.GetGenericTypeName(), request);
var response = await next();
_logger.LogInformation("----- Command {CommandName} handled - response: {@Response}", request.GetGenericTypeName(), response);
return response;
}
}
}