Skip to content

Commit f9b0587

Browse files
committed
Fixed missing logger issue in tests
1 parent f6da24c commit f9b0587

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

Fritz.InstantAPIs.sln

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
1717
.editorconfig = .editorconfig
1818
CODE-OF-CONDUCT.md = CODE-OF-CONDUCT.md
1919
CONTRIBUTING.md = CONTRIBUTING.md
20+
RELEASE_NOTES.txt = RELEASE_NOTES.txt
2021
EndProjectSection
2122
EndProject
2223
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Test", "Test\Test.csproj", "{CD123B01-1B52-4E80-84F7-4D10E01EE10F}"

Fritz.InstantAPIs/WebApplicationExtensions.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using Microsoft.Extensions.DependencyInjection;
33
using Microsoft.Extensions.Hosting;
44
using Microsoft.Extensions.Logging;
5+
using Microsoft.Extensions.Logging.Abstractions;
56
using Microsoft.Extensions.Options;
67
using System.Reflection;
78

@@ -36,8 +37,12 @@ public static IEndpointRouteBuilder MapInstantAPIs<D>(this IEndpointRouteBuilder
3637
private static void MapInstantAPIsUsingReflection<D>(IEndpointRouteBuilder app, IEnumerable<TypeTable> requestedTables) where D : DbContext
3738
{
3839

39-
var loggerFactory = app.ServiceProvider.GetRequiredService<ILoggerFactory>();
40-
var logger = loggerFactory.CreateLogger(LOGGER_CATEGORY_NAME);
40+
ILogger logger = NullLogger.Instance;
41+
if (app.ServiceProvider != null)
42+
{
43+
var loggerFactory = app.ServiceProvider.GetRequiredService<ILoggerFactory>();
44+
logger = loggerFactory.CreateLogger(LOGGER_CATEGORY_NAME);
45+
}
4146

4247
var allMethods = typeof(MapApiExtensions).GetMethods(BindingFlags.NonPublic | BindingFlags.Static).Where(m => m.Name.StartsWith("Map")).ToArray();
4348
var initialize = typeof(MapApiExtensions).GetMethod("Initialize", BindingFlags.NonPublic | BindingFlags.Static);

0 commit comments

Comments
 (0)