diff --git a/source/EasyWay/Internals/Commands/Commands/CommandExecutorLoggerDecorator.cs b/source/EasyWay/Internals/Commands/Commands/CommandExecutorLoggerDecorator.cs index 02b52b7..f66f99f 100644 --- a/source/EasyWay/Internals/Commands/Commands/CommandExecutorLoggerDecorator.cs +++ b/source/EasyWay/Internals/Commands/Commands/CommandExecutorLoggerDecorator.cs @@ -23,9 +23,18 @@ public async Task Execute(TCommand command, Ca { var logger = _serviceProvider.GetRequiredService>(); + var userContext = _serviceProvider.GetRequiredService(); + //TODO begin scope (correlation Id, userId) - logger.Executing(command); + if (userContext.UserId is not null) + { + logger.ExecutingByUser(command, userContext.UserId); + } + else + { + logger.Executing(command); + } try { diff --git a/source/EasyWay/Internals/Commands/CommandsWithResult/CommandWithOperationResultExecutorLoggerDecorator.cs b/source/EasyWay/Internals/Commands/CommandsWithResult/CommandWithOperationResultExecutorLoggerDecorator.cs index ae80484..f82ec09 100644 --- a/source/EasyWay/Internals/Commands/CommandsWithResult/CommandWithOperationResultExecutorLoggerDecorator.cs +++ b/source/EasyWay/Internals/Commands/CommandsWithResult/CommandWithOperationResultExecutorLoggerDecorator.cs @@ -24,9 +24,18 @@ public async Task> Command>(); + var userContext = _serviceProvider.GetRequiredService(); + //TODO begin scope (correlation Id, userId) - logger.Executing(command); + if (userContext.UserId is not null) + { + logger.ExecutingByUser(command, userContext.UserId); + } + else + { + logger.Executing(command); + } try { diff --git a/source/EasyWay/Internals/Loggers/EasyWayLogger.cs b/source/EasyWay/Internals/Loggers/EasyWayLogger.cs index ee2d8e6..7ab3cd6 100644 --- a/source/EasyWay/Internals/Loggers/EasyWayLogger.cs +++ b/source/EasyWay/Internals/Loggers/EasyWayLogger.cs @@ -1,5 +1,4 @@ -using EasyWay.Internals.BusinessRules; -using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Logging; namespace EasyWay.Internals.Queries.Loggers { @@ -13,6 +12,9 @@ internal sealed partial class EasyWayLogger [LoggerMessage(0, LogLevel.Information, "Executing {@component}", SkipEnabledCheck = true)] public partial void Executing(object component); + [LoggerMessage(0, LogLevel.Information, "Executing {@component} by @userId", SkipEnabledCheck = true)] + public partial void ExecutingByUser(object component, string userId); + [LoggerMessage(1, LogLevel.Information, "Successed", SkipEnabledCheck = true)] public partial void Successed(); diff --git a/source/EasyWay/Internals/Queries/QueryExecutorLoggerDecorator.cs b/source/EasyWay/Internals/Queries/QueryExecutorLoggerDecorator.cs index a6b2ea1..092859d 100644 --- a/source/EasyWay/Internals/Queries/QueryExecutorLoggerDecorator.cs +++ b/source/EasyWay/Internals/Queries/QueryExecutorLoggerDecorator.cs @@ -25,9 +25,18 @@ public async Task> Execute( { var logger = _serviceProvider.GetRequiredService>(); + var userContext = _serviceProvider.GetRequiredService(); + //TODO begin scope (correlation Id, userId) - logger.Executing(query); + if (userContext.UserId is not null) + { + logger.ExecutingByUser(query, userContext.UserId); + } + else + { + logger.Executing(query); + } try {