From d5f4bf77fb0b2cedacefe91b76c09d06698720c0 Mon Sep 17 00:00:00 2001 From: Haik Date: Thu, 29 Aug 2024 16:53:44 +0400 Subject: [PATCH] behavior delete --- .../Behaviors/LoggingBehavior.cs | 50 ------------------- 1 file changed, 50 deletions(-) delete mode 100644 src/Pandatech.CleanArchitecture.Core/Behaviors/LoggingBehavior.cs diff --git a/src/Pandatech.CleanArchitecture.Core/Behaviors/LoggingBehavior.cs b/src/Pandatech.CleanArchitecture.Core/Behaviors/LoggingBehavior.cs deleted file mode 100644 index 0cff0ac..0000000 --- a/src/Pandatech.CleanArchitecture.Core/Behaviors/LoggingBehavior.cs +++ /dev/null @@ -1,50 +0,0 @@ -using System.Diagnostics; -using System.Reflection; -using MediatR; -using Microsoft.Extensions.Hosting; -using Microsoft.Extensions.Logging; - -namespace Pandatech.CleanArchitecture.Core.Behaviors; - -public class LoggingBehavior(ILogger logger, IHostEnvironment environment) - : IPipelineBehavior - where TRequest : IRequest -{ - public async Task Handle(TRequest request, - RequestHandlerDelegate next, - CancellationToken cancellationToken) - { - if (request is null) - { - throw new ArgumentNullException(nameof(request)); - } - - if (logger.IsEnabled(LogLevel.Information)) - { - logger.LogInformation("Handling {RequestName}", typeof(TRequest).Name); - - // Reflection! Could be a performance concern and also expose sensitive data - if (!environment.IsProduction()) - { - var myType = request.GetType(); - IList props = new List(myType.GetProperties()); - foreach (var prop in props) - { - var propValue = prop.GetValue(request, null); - logger.LogInformation("Property {Property} : {@Value}", prop.Name, propValue); - } - } - } - - var sw = Stopwatch.StartNew(); - - var response = await next(); - sw.Stop(); - - logger.LogInformation("Handled {RequestName} with {Response} in {Ms} ms", - typeof(TRequest).Name, - response, - sw.ElapsedMilliseconds); - return response; - } -} \ No newline at end of file