Class ResultLoggerServiceCollectionExtensions
Registers FluentLogger as the logger used by FluentResults (LogIfFailed, Log, ...).
public static class ResultLoggerServiceCollectionExtensions
- Inheritance
-
ResultLoggerServiceCollectionExtensions
- Inherited Members
Methods
AddResultLogger(IServiceCollection)
Registers FluentLogger as the FluentResults.IResultLogger (singleton, unless one is already registered) and a hosted service
that gives it to FluentResults with Result.Setup when the host starts. That hosted service is registered first, so it runs
before the other hosted services (unless HostOptions.ServicesStartConcurrently is set).
public static IServiceCollection AddResultLogger(this IServiceCollection services)
Parameters
servicesIServiceCollectionThe service collection.
Returns
- IServiceCollection
The service collection, to chain calls.
Examples
builder.Services.AddApplicationContext();
builder.Services.AddResultLogger();
Remarks
FluentLogger needs the Arc4u ILogger<T>: also call AddApplicationContext() (or AddILogger()).
Results logged before the host starts (code between Build() and Run()) or without a host are not logged:
call UseResultLogger(IServiceProvider) right after the service provider is built.
UseResultLogger(IServiceProvider)
Gives the registered FluentResults.IResultLogger to FluentResults with Result.Setup.
public static IServiceProvider UseResultLogger(this IServiceProvider serviceProvider)
Parameters
serviceProviderIServiceProviderThe built service provider.
Returns
- IServiceProvider
The same
serviceProvider.