Skip to content

Commit 765cc6f

Browse files
committed
Fixed bug with error logging middleware DI
1 parent 25ed51f commit 765cc6f

File tree

2 files changed

+8
-11
lines changed

2 files changed

+8
-11
lines changed

src/Cofoundry.Plugins.ErrorLogging/Bootstrap/ErrorDependencyRegistration.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
using Cofoundry.Core.DependencyInjection;
77
using Cofoundry.Plugins.ErrorLogging.Domain;
88
using Cofoundry.Plugins.ErrorLogging.Data;
9-
using Cofoundry.Core.Configuration;
109

1110
namespace Cofoundry.Plugins.ErrorLogging.Bootstrap
1211
{

src/Cofoundry.Plugins.ErrorLogging/Middleware/ErrorLoggingMiddleware.cs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,19 @@ namespace Cofoundry.Plugins.ErrorLogging
1111
public class ErrorLoggingMiddleware
1212
{
1313
private readonly RequestDelegate _next;
14-
private readonly IErrorLoggingService _errorLoggingService;
15-
private readonly ILogger<ErrorLoggingMiddleware> _logger;
1614

1715
public ErrorLoggingMiddleware(
18-
RequestDelegate next,
19-
ILogger<ErrorLoggingMiddleware> logger,
20-
IErrorLoggingService errorLoggingService
16+
RequestDelegate next
2117
)
2218
{
2319
_next = next;
24-
_logger = logger;
25-
_errorLoggingService = errorLoggingService;
2620
}
2721

28-
public async Task Invoke(HttpContext context)
22+
public async Task Invoke(
23+
HttpContext context,
24+
ILogger<ErrorLoggingMiddleware> logger,
25+
IErrorLoggingService errorLoggingService
26+
)
2927
{
3028
try
3129
{
@@ -35,14 +33,14 @@ public async Task Invoke(HttpContext context)
3533
{
3634
try
3735
{
38-
await _errorLoggingService.LogAsync(ex);
36+
await errorLoggingService.LogAsync(ex);
3937
}
4038
catch (Exception loggingEx)
4139
{
4240
// The original exception should still be logged by the outer handler, here we
4341
// just log loggingEx
4442
var msg = "An error occured logging exception {0} using handler type {1}";
45-
_logger.LogError(0, loggingEx, msg, ex.GetType().FullName, _errorLoggingService.GetType().FullName);
43+
logger.LogError(0, loggingEx, msg, ex.GetType().FullName, errorLoggingService.GetType().FullName);
4644
}
4745

4846
throw;

0 commit comments

Comments
 (0)