Skip to content

Commit 936fefc

Browse files
committed
logger
1 parent 20bbf79 commit 936fefc

11 files changed

+34
-30
lines changed

src/CommandQuery.AWSLambda/CommandFunction.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ public CommandFunction(ICommandProcessor commandProcessor, JsonSerializerOptions
2626
}
2727

2828
/// <inheritdoc />
29-
public async Task<APIGatewayProxyResponse> HandleAsync(string commandName, APIGatewayProxyRequest request, ILambdaLogger? logger)
29+
public async Task<APIGatewayProxyResponse> HandleAsync(string commandName, APIGatewayProxyRequest request, ILambdaLogger logger)
3030
{
31-
logger?.LogLine($"Handle {commandName}");
31+
logger.LogLine($"Handle {commandName}");
3232

3333
if (request is null)
3434
{
@@ -48,16 +48,16 @@ public async Task<APIGatewayProxyResponse> HandleAsync(string commandName, APIGa
4848
}
4949
catch (Exception exception)
5050
{
51-
logger?.LogLine($"Handle command failed: {commandName}, {request.Body}, {exception.Message}");
51+
logger.LogLine($"Handle command failed: {commandName}, {request.Body}, {exception.Message}");
5252

5353
return exception.IsHandled() ? request.BadRequest(exception, _options) : request.InternalServerError(exception, _options);
5454
}
5555
}
5656

5757
/// <inheritdoc />
58-
public async Task<APIGatewayHttpApiV2ProxyResponse> HandleAsync(string commandName, APIGatewayHttpApiV2ProxyRequest request, ILambdaLogger? logger)
58+
public async Task<APIGatewayHttpApiV2ProxyResponse> HandleAsync(string commandName, APIGatewayHttpApiV2ProxyRequest request, ILambdaLogger logger)
5959
{
60-
logger?.LogLine($"Handle {commandName}");
60+
logger.LogLine($"Handle {commandName}");
6161

6262
if (request is null)
6363
{
@@ -77,7 +77,7 @@ public async Task<APIGatewayHttpApiV2ProxyResponse> HandleAsync(string commandNa
7777
}
7878
catch (Exception exception)
7979
{
80-
logger?.LogLine($"Handle command failed: {commandName}, {request.Body}, {exception.Message}");
80+
logger.LogLine($"Handle command failed: {commandName}, {request.Body}, {exception.Message}");
8181

8282
return exception.IsHandled() ? request.BadRequest(exception, _options) : request.InternalServerError(exception, _options);
8383
}

src/CommandQuery.AWSLambda/ICommandFunction.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public interface ICommandFunction
1616
/// <param name="logger">An <see cref="ILambdaLogger"/>.</param>
1717
/// <returns>The result for status code <c>200</c>, or an error for status code <c>400</c> and <c>500</c>.</returns>
1818
/// <exception cref="ArgumentNullException"><paramref name="request"/> is <see langword="null"/>.</exception>
19-
Task<APIGatewayProxyResponse> HandleAsync(string commandName, APIGatewayProxyRequest request, ILambdaLogger? logger);
19+
Task<APIGatewayProxyResponse> HandleAsync(string commandName, APIGatewayProxyRequest request, ILambdaLogger logger);
2020

2121
/// <summary>
2222
/// Handle a command.
@@ -26,6 +26,6 @@ public interface ICommandFunction
2626
/// <param name="logger">An <see cref="ILambdaLogger"/>.</param>
2727
/// <returns>The result for status code <c>200</c>, or an error for status code <c>400</c> and <c>500</c>.</returns>
2828
/// <exception cref="ArgumentNullException"><paramref name="request"/> is <see langword="null"/>.</exception>
29-
Task<APIGatewayHttpApiV2ProxyResponse> HandleAsync(string commandName, APIGatewayHttpApiV2ProxyRequest request, ILambdaLogger? logger);
29+
Task<APIGatewayHttpApiV2ProxyResponse> HandleAsync(string commandName, APIGatewayHttpApiV2ProxyRequest request, ILambdaLogger logger);
3030
}
3131
}

src/CommandQuery.AWSLambda/IQueryFunction.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public interface IQueryFunction
1616
/// <param name="logger">An <see cref="ILambdaLogger"/>.</param>
1717
/// <returns>The result for status code <c>200</c>, or an error for status code <c>400</c> and <c>500</c>.</returns>
1818
/// <exception cref="ArgumentNullException"><paramref name="request"/> is <see langword="null"/>.</exception>
19-
Task<APIGatewayProxyResponse> HandleAsync(string queryName, APIGatewayProxyRequest request, ILambdaLogger? logger);
19+
Task<APIGatewayProxyResponse> HandleAsync(string queryName, APIGatewayProxyRequest request, ILambdaLogger logger);
2020

2121
/// <summary>
2222
/// Handle a query.
@@ -26,6 +26,6 @@ public interface IQueryFunction
2626
/// <param name="logger">An <see cref="ILambdaLogger"/>.</param>
2727
/// <returns>The result for status code <c>200</c>, or an error for status code <c>400</c> and <c>500</c>.</returns>
2828
/// <exception cref="ArgumentNullException"><paramref name="request"/> is <see langword="null"/>.</exception>
29-
Task<APIGatewayHttpApiV2ProxyResponse> HandleAsync(string queryName, APIGatewayHttpApiV2ProxyRequest request, ILambdaLogger? logger);
29+
Task<APIGatewayHttpApiV2ProxyResponse> HandleAsync(string queryName, APIGatewayHttpApiV2ProxyRequest request, ILambdaLogger logger);
3030
}
3131
}

src/CommandQuery.AWSLambda/QueryFunction.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ public QueryFunction(IQueryProcessor queryProcessor, JsonSerializerOptions? opti
2525
}
2626

2727
/// <inheritdoc />
28-
public async Task<APIGatewayProxyResponse> HandleAsync(string queryName, APIGatewayProxyRequest request, ILambdaLogger? logger)
28+
public async Task<APIGatewayProxyResponse> HandleAsync(string queryName, APIGatewayProxyRequest request, ILambdaLogger logger)
2929
{
30-
logger?.LogLine($"Handle {queryName}");
30+
logger.LogLine($"Handle {queryName}");
3131

3232
if (request is null)
3333
{
@@ -45,7 +45,7 @@ public async Task<APIGatewayProxyResponse> HandleAsync(string queryName, APIGate
4545
catch (Exception exception)
4646
{
4747
var payload = request.HttpMethod == "GET" ? request.Path : request.Body;
48-
logger?.LogLine($"Handle query failed: {queryName}, {payload}, {exception.Message}");
48+
logger.LogLine($"Handle query failed: {queryName}, {payload}, {exception.Message}");
4949

5050
return exception.IsHandled() ? request.BadRequest(exception, _options) : request.InternalServerError(exception, _options);
5151
}
@@ -57,9 +57,9 @@ static Dictionary<string, IEnumerable<string>> Dictionary(IDictionary<string, IL
5757
}
5858

5959
/// <inheritdoc />
60-
public async Task<APIGatewayHttpApiV2ProxyResponse> HandleAsync(string queryName, APIGatewayHttpApiV2ProxyRequest request, ILambdaLogger? logger)
60+
public async Task<APIGatewayHttpApiV2ProxyResponse> HandleAsync(string queryName, APIGatewayHttpApiV2ProxyRequest request, ILambdaLogger logger)
6161
{
62-
logger?.LogLine($"Handle {queryName}");
62+
logger.LogLine($"Handle {queryName}");
6363

6464
if (request is null)
6565
{
@@ -77,7 +77,7 @@ public async Task<APIGatewayHttpApiV2ProxyResponse> HandleAsync(string queryName
7777
catch (Exception exception)
7878
{
7979
var payload = request.RequestContext.Http.Method == "GET" ? request.RequestContext.Http.Path : request.Body;
80-
logger?.LogLine($"Handle query failed: {queryName}, {payload}, {exception.Message}");
80+
logger.LogLine($"Handle query failed: {queryName}, {payload}, {exception.Message}");
8181

8282
return exception.IsHandled() ? request.BadRequest(exception, _options) : request.InternalServerError(exception, _options);
8383
}

src/CommandQuery.AspNetCore/CommandQuery.AspNetCore.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131

3232
<ItemGroup>
3333
<InternalsVisibleTo Include="CommandQuery.AspNetCore.Tests" />
34+
<InternalsVisibleTo Include="DynamicProxyGenAssembly2" />
3435
</ItemGroup>
3536

3637
<ItemGroup>

src/CommandQuery.AspNetCore/CommandWithResultController.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ internal class CommandController<TCommand, TResult> : ControllerBase
1111
where TCommand : ICommand<TResult>
1212
{
1313
private readonly ICommandProcessor _commandProcessor;
14-
private readonly ILogger? _logger;
14+
private readonly ILogger _logger;
1515

1616
/// <summary>
1717
/// Initializes a new instance of the <see cref="CommandController{TCommand,TResult}"/> class.
@@ -33,7 +33,7 @@ public CommandController(ICommandProcessor commandProcessor, ILogger<CommandCont
3333
[HttpPost]
3434
public async Task<IActionResult> HandleAsync(TCommand command, CancellationToken cancellationToken)
3535
{
36-
_logger?.LogInformation("Handle {@Command}", command);
36+
_logger.LogInformation("Handle {@Command}", command);
3737

3838
try
3939
{
@@ -43,7 +43,7 @@ public async Task<IActionResult> HandleAsync(TCommand command, CancellationToken
4343
}
4444
catch (Exception exception)
4545
{
46-
_logger?.LogError(exception, "Handle command failed: {@Command}", command);
46+
_logger.LogError(exception, "Handle command failed: {@Command}", command);
4747

4848
return exception.IsHandled() ? BadRequest(exception.ToError()) : StatusCode(500, exception.ToError());
4949
}

src/CommandQuery.AspNetCore/CommandWithoutResultController.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ internal class CommandController<TCommand> : ControllerBase
1111
where TCommand : ICommand
1212
{
1313
private readonly ICommandProcessor _commandProcessor;
14-
private readonly ILogger? _logger;
14+
private readonly ILogger _logger;
1515

1616
/// <summary>
1717
/// Initializes a new instance of the <see cref="CommandController{TCommand}"/> class.
@@ -33,7 +33,7 @@ public CommandController(ICommandProcessor commandProcessor, ILogger<CommandCont
3333
[HttpPost]
3434
public async Task<IActionResult> HandleAsync(TCommand command, CancellationToken cancellationToken)
3535
{
36-
_logger?.LogInformation("Handle {@Command}", command);
36+
_logger.LogInformation("Handle {@Command}", command);
3737

3838
try
3939
{
@@ -43,7 +43,7 @@ public async Task<IActionResult> HandleAsync(TCommand command, CancellationToken
4343
}
4444
catch (Exception exception)
4545
{
46-
_logger?.LogError(exception, "Handle command failed: {@Command}", command);
46+
_logger.LogError(exception, "Handle command failed: {@Command}", command);
4747

4848
return exception.IsHandled() ? BadRequest(exception.ToError()) : StatusCode(500, exception.ToError());
4949
}

src/CommandQuery.AspNetCore/QueryController.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ internal class QueryController<TQuery, TResult> : ControllerBase
1212
where TQuery : IQuery<TResult>
1313
{
1414
private readonly IQueryProcessor _queryProcessor;
15-
private readonly ILogger? _logger;
15+
private readonly ILogger _logger;
1616

1717
/// <summary>
1818
/// Initializes a new instance of the <see cref="QueryController{TQuery,TResult}"/> class.
@@ -34,7 +34,7 @@ public QueryController(IQueryProcessor queryProcessor, ILogger<QueryController<T
3434
[HttpPost]
3535
public async Task<IActionResult> HandlePostAsync(TQuery query, CancellationToken cancellationToken)
3636
{
37-
_logger?.LogInformation("Handle {@Query}", query);
37+
_logger.LogInformation("Handle {@Query}", query);
3838

3939
try
4040
{
@@ -44,7 +44,7 @@ public async Task<IActionResult> HandlePostAsync(TQuery query, CancellationToken
4444
}
4545
catch (Exception exception)
4646
{
47-
_logger?.LogError(exception, "Handle query failed: {@Query}", query);
47+
_logger.LogError(exception, "Handle query failed: {@Query}", query);
4848

4949
return exception.IsHandled() ? BadRequest(exception.ToError()) : StatusCode(500, exception.ToError());
5050
}
@@ -59,7 +59,7 @@ public async Task<IActionResult> HandlePostAsync(TQuery query, CancellationToken
5959
[HttpGet]
6060
public async Task<IActionResult> HandleGetAsync([FromQuery] TQuery query, CancellationToken cancellationToken)
6161
{
62-
_logger?.LogInformation("Handle {@Query}", query);
62+
_logger.LogInformation("Handle {@Query}", query);
6363

6464
try
6565
{
@@ -69,7 +69,7 @@ public async Task<IActionResult> HandleGetAsync([FromQuery] TQuery query, Cancel
6969
}
7070
catch (Exception exception)
7171
{
72-
_logger?.LogError(exception, "Handle query failed: {@Query}", query);
72+
_logger.LogError(exception, "Handle query failed: {@Query}", query);
7373

7474
return exception.IsHandled() ? BadRequest(exception.ToError()) : StatusCode(500, exception.ToError());
7575
}

tests/CommandQuery.AspNetCore.Tests/CommandControllerWithResultTests.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using FluentAssertions;
44
using LoFuUnit.NUnit;
55
using Microsoft.AspNetCore.Mvc;
6+
using Microsoft.Extensions.Logging;
67
using Moq;
78
using NUnit.Framework;
89

@@ -14,7 +15,7 @@ public class CommandControllerWithResultTests
1415
public void SetUp()
1516
{
1617
FakeCommandProcessor = new Mock<ICommandProcessor>();
17-
Subject = new CommandController<FakeResultCommand, FakeResult>(FakeCommandProcessor.Object, null);
18+
Subject = new CommandController<FakeResultCommand, FakeResult>(FakeCommandProcessor.Object, new Mock<ILogger<CommandController<FakeResultCommand, FakeResult>>>().Object);
1819
}
1920

2021
[LoFu, Test]

tests/CommandQuery.AspNetCore.Tests/CommandControllerWithoutResultTests.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using FluentAssertions;
44
using LoFuUnit.NUnit;
55
using Microsoft.AspNetCore.Mvc;
6+
using Microsoft.Extensions.Logging;
67
using Moq;
78
using NUnit.Framework;
89

@@ -14,7 +15,7 @@ public class CommandControllerWithoutResultTests
1415
public void SetUp()
1516
{
1617
FakeCommandProcessor = new Mock<ICommandProcessor>();
17-
Subject = new CommandController<FakeCommand>(FakeCommandProcessor.Object, null);
18+
Subject = new CommandController<FakeCommand>(FakeCommandProcessor.Object, new Mock<ILogger<CommandController<FakeCommand>>>().Object);
1819
}
1920

2021
[LoFu, Test]

tests/CommandQuery.AspNetCore.Tests/QueryControllerTests.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using FluentAssertions;
44
using LoFuUnit.NUnit;
55
using Microsoft.AspNetCore.Mvc;
6+
using Microsoft.Extensions.Logging;
67
using Moq;
78
using NUnit.Framework;
89

@@ -14,7 +15,7 @@ public class QueryControllerTests
1415
public void SetUp()
1516
{
1617
FakeQueryProcessor = new Mock<IQueryProcessor>();
17-
Subject = new QueryController<FakeQuery, FakeResult>(FakeQueryProcessor.Object, null);
18+
Subject = new QueryController<FakeQuery, FakeResult>(FakeQueryProcessor.Object, new Mock<ILogger<QueryController<FakeQuery, FakeResult>>>().Object);
1819
}
1920

2021
[LoFu, Test]

0 commit comments

Comments
 (0)