Skip to content

Commit

Permalink
Fixed missing logger issue in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
csharpfritz committed Feb 27, 2022
1 parent f6da24c commit f9b0587
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
1 change: 1 addition & 0 deletions Fritz.InstantAPIs.sln
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
.editorconfig = .editorconfig
CODE-OF-CONDUCT.md = CODE-OF-CONDUCT.md
CONTRIBUTING.md = CONTRIBUTING.md
RELEASE_NOTES.txt = RELEASE_NOTES.txt
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Test", "Test\Test.csproj", "{CD123B01-1B52-4E80-84F7-4D10E01EE10F}"
Expand Down
9 changes: 7 additions & 2 deletions Fritz.InstantAPIs/WebApplicationExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using Microsoft.Extensions.Options;
using System.Reflection;

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

var loggerFactory = app.ServiceProvider.GetRequiredService<ILoggerFactory>();
var logger = loggerFactory.CreateLogger(LOGGER_CATEGORY_NAME);
ILogger logger = NullLogger.Instance;
if (app.ServiceProvider != null)
{
var loggerFactory = app.ServiceProvider.GetRequiredService<ILoggerFactory>();
logger = loggerFactory.CreateLogger(LOGGER_CATEGORY_NAME);
}

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

0 comments on commit f9b0587

Please sign in to comment.