Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,18 @@ public async Task<CommandResult> Execute<TModule, TCommand>(TCommand command, Ca
{
var logger = _serviceProvider.GetRequiredService<EasyWayLogger<TModule>>();

var userContext = _serviceProvider.GetRequiredService<IUserContext>();

//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
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,18 @@ public async Task<CommandResult<TOperationResult>> Command<TModule, TCommand, TO
{
var logger = _serviceProvider.GetRequiredService<EasyWayLogger<TModule>>();

var userContext = _serviceProvider.GetRequiredService<IUserContext>();

//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
{
Expand Down
6 changes: 4 additions & 2 deletions source/EasyWay/Internals/Loggers/EasyWayLogger.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using EasyWay.Internals.BusinessRules;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging;

namespace EasyWay.Internals.Queries.Loggers
{
Expand All @@ -13,6 +12,9 @@
[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);

Check warning on line 16 in source/EasyWay/Internals/Loggers/EasyWayLogger.cs

View workflow job for this annotation

GitHub Actions / Build & Tests

Argument 'userId' is not referenced from the logging message (https://learn.microsoft.com/dotnet/fundamentals/syslib-diagnostics/syslib1015)

[LoggerMessage(1, LogLevel.Information, "Successed", SkipEnabledCheck = true)]
public partial void Successed();

Expand Down
11 changes: 10 additions & 1 deletion source/EasyWay/Internals/Queries/QueryExecutorLoggerDecorator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,18 @@
{
var logger = _serviceProvider.GetRequiredService<EasyWayLogger<TModule>>();

var userContext = _serviceProvider.GetRequiredService<IUserContext>();

//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
{
Expand All @@ -35,12 +44,12 @@

switch (result.Error)
{
case QueryErrorEnum.None: logger.Successed(result.ReadModel); break;

Check warning on line 47 in source/EasyWay/Internals/Queries/QueryExecutorLoggerDecorator.cs

View workflow job for this annotation

GitHub Actions / Build & Tests

Possible null reference argument for parameter 'result' in 'void EasyWayLogger<TModule>.Successed(object result)'.
case QueryErrorEnum.Validation: logger.Validation(result.ValidationErrors); break;
case QueryErrorEnum.OperationCanceled: logger.OperationCanceled(); break;
case QueryErrorEnum.NotFound: logger.NotFound(); break;
case QueryErrorEnum.Forbidden: logger.Forbidden(); break;
default: logger.UnexpectedException(result.Exception); break;

Check warning on line 52 in source/EasyWay/Internals/Queries/QueryExecutorLoggerDecorator.cs

View workflow job for this annotation

GitHub Actions / Build & Tests

Possible null reference argument for parameter 'exception' in 'void EasyWayLogger<TModule>.UnexpectedException(Exception exception)'.
}

return result;
Expand Down
Loading