Skip to content

NeedlrBootstrapperExtensions

NexusLabs.Needlr.Hosting

NeedlrBootstrapperExtensions Class

Extension methods for configuring NeedlrBootstrapper instances.

public static class NeedlrBootstrapperExtensions

Inheritance System.Object 🡒 NeedlrBootstrapperExtensions

Methods

NeedlrBootstrapperExtensions.UsingLoggerFactory(this NeedlrBootstrapper, ILoggerFactory) Method

Overrides the default console logger factory with a custom Microsoft.Extensions.Logging.ILoggerFactory.

public static NexusLabs.Needlr.Hosting.NeedlrBootstrapper UsingLoggerFactory(this NexusLabs.Needlr.Hosting.NeedlrBootstrapper bootstrapper, Microsoft.Extensions.Logging.ILoggerFactory loggerFactory);

Parameters

bootstrapper NeedlrBootstrapper

The bootstrapper to configure.

loggerFactory Microsoft.Extensions.Logging.ILoggerFactory

The logger factory to use.

Returns

NeedlrBootstrapper
A new NeedlrBootstrapper with the factory applied.

Example

await new NeedlrBootstrapper()
    .UsingLoggerFactory(myLoggerFactory)
    .RunAsync(async (ctx, ct) => { /* ... */ });

NeedlrBootstrapperExtensions.WithCleanup(this NeedlrBootstrapper, Func<Task>) Method

Registers an async cleanup callback that runs in the finally block of RunAsync(Func<NeedlrBootstrapContext,CancellationToken,Task>, CancellationToken), regardless of whether the application succeeds or throws.

public static NexusLabs.Needlr.Hosting.NeedlrBootstrapper WithCleanup(this NexusLabs.Needlr.Hosting.NeedlrBootstrapper bootstrapper, System.Func<System.Threading.Tasks.Task> cleanup);

Parameters

bootstrapper NeedlrBootstrapper

The bootstrapper to configure.

cleanup System.Func<System.Threading.Tasks.Task>

The async cleanup delegate (e.g. flushing a log sink).

Returns

NeedlrBootstrapper
A new NeedlrBootstrapper with the cleanup registered.

Example

await new NeedlrBootstrapper()
    .WithCleanup(async () => await FlushLogsAsync())
    .RunAsync(async (ctx, ct) => { /* ... */ });