Logging

Sometimes we want to show the app logs in unit tests for easier debugging. So TestOutputLoggerProvider can help us.

    using Juice.Extensions.DependencyInjection;
    using Microsoft.Extensions.Logging;
    ...

    var builder = new DependencyResolver();
    builder.ConfigureServices(services =>
    {
        var configService = services.BuildServiceProvider().GetRequiredService<IConfigurationService>();
        var configuration = configService.GetConfiguration();

        services.AddLogging(builder =>
        {
            builder.ClearProviders()
            .AddTestOutputLogger()
            .AddConfiguration(configuration.GetSection("Logging"));
        });

        // must register an instance of ITestOutputHelper
        services.AddSingleton(_output);
        // configure other services
        ...
    });

The library can be accessed via Nuget: