26.251. Class ExceptionManager

Namespace: ArmoniK.Core.Common.Utils
Assembly: ArmoniK.Core.Common.dll

Manage exceptions at the whole application level. If too many exceptions are thrown, the application is stopped. When the application is stopped, a grace delay is in place to let all the running services to stop properly.

public class ExceptionManager : IDisposable, IHostApplicationLifetime, IHostLifetime

26.251.1. Inheritance

objectExceptionManager

26.251.2. Implements

IDisposable, IHostApplicationLifetime, IHostLifetime

26.251.3. Inherited Members

object.Equals(object?), object.Equals(object?, object?), object.GetHashCode(), object.GetType(), object.MemberwiseClone(), object.ReferenceEquals(object?, object?), object.ToString()

26.251.4. Constructors

26.251.4.1. ExceptionManager(IHostApplicationLifetime, IOptions<ConsoleLifetimeOptions>, IHostEnvironment, IOptions<HostOptions>, ILogger<ExceptionManager>?, Options?)

Build an ExceptionManager

public ExceptionManager(IHostApplicationLifetime applicationLifetime, IOptions<ConsoleLifetimeOptions> consoleLifetimeOptions, IHostEnvironment environment, IOptions<HostOptions> hostOptions, ILogger<ExceptionManager>? logger = null, ExceptionManager.Options? options = null)

26.251.4.1.1. Parameters

applicationLifetime IHostApplicationLifetime

The lifetime of the application

consoleLifetimeOptions IOptions<ConsoleLifetimeOptions>

environment IHostEnvironment

hostOptions IOptions<HostOptions>

logger ILogger<ExceptionManager>?

The logger for the ExceptionManager

options ExceptionManager.Options?

Options for the ExceptionManager

26.251.5. Properties

26.251.5.1. ApplicationStarted

Gets a cancellation token. Triggered when the application host has fully started.

public CancellationToken ApplicationStarted { get; }

26.251.5.1.1. Property Value

CancellationToken

26.251.5.2. ApplicationStopped

Gets a cancellation token. Triggered when the application host has completed a graceful shutdown. The application will not exit until all callbacks registered on this token have completed.

public CancellationToken ApplicationStopped { get; }

26.251.5.2.1. Property Value

CancellationToken

26.251.5.3. ApplicationStopping

Gets a cancellation token. Triggered when the application host is starting a graceful shutdown. Shutdown will block until all callbacks registered on this token have completed.

public CancellationToken ApplicationStopping { get; }

26.251.5.3.1. Property Value

CancellationToken

26.251.5.4. EarlyCancellationToken

CancellationToken that is triggered as soon as the application is stopped, or too many errors were thrown

public CancellationToken EarlyCancellationToken { get; }

26.251.5.4.1. Property Value

CancellationToken

26.251.5.5. Failed

Whether there were too many errors

public bool Failed { get; }

26.251.5.5.1. Property Value

bool

26.251.5.6. LateCancellationToken

CancellationToken that is triggered after a grace delay

public CancellationToken LateCancellationToken { get; }

26.251.5.6.1. Property Value

CancellationToken

26.251.6. Methods

26.251.6.1. Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

public void Dispose()

26.251.6.2. FatalError(ILogger?, Exception?, string, params object?[])

Record a fatal error at the application level and trigger

public void FatalError(ILogger? logger, Exception? e, string message, params object?[] args)

26.251.6.2.1. Parameters

logger ILogger?

Logger used to log the error

e Exception?

Exception to log, if any

message string

Message to log

args object?[]

Arguments for the log message

26.251.6.2.2. Remarks

If logger is null, the logger of

this
is used.

Following errors are logged as Warnings instead of Errors

26.251.6.3. RecordError(ILogger?, Exception?, string, params object?[])

Record an error at the application level

public void RecordError(ILogger? logger, Exception? e, string message, params object?[] args)

26.251.6.3.1. Parameters

logger ILogger?

Logger used to log the error

e Exception?

Exception to log, if any

message string

Message to log

args object?[]

Arguments for the log message

26.251.6.3.2. Remarks

If logger is null, the logger of

this
is used.

If the maximum number of errors is reached, it will trigger the , and make the following errors logged as Warnings instead of Errors.

26.251.6.4. RecordSuccess(ILogger?)

Decrease the number of recorded errors to indicate that the application is behaving correctly.

public void RecordSuccess(ILogger? logger = null)

26.251.6.4.1. Parameters

logger ILogger?

Logger used to log the success

26.251.6.4.2. Remarks

If logger is null, the logger of

this
is used.

If the ExceptionManager is already in Failed state, this call does nothing.

26.251.6.5. Register()

Registers a class that has to call to trigger application stop.

public void Register()

26.251.6.6. StopApplication()

Requests termination of the current application.

public void StopApplication()

26.251.6.7. StopApplication(bool)

Requests termination of the current application.

public void StopApplication(bool external)

26.251.6.7.1. Parameters

external bool

Whether cancellation is external

26.251.6.8. StopAsync(CancellationToken)

Called from to indicate that the host is stopping and it’s time to shut down.

public Task StopAsync(CancellationToken cancellationToken)

26.251.6.8.1. Parameters

cancellationToken CancellationToken

Used to indicate when stop should no longer be graceful.

26.251.6.8.2. Returns

Task

A .

26.251.6.9. UnregisterAndStop(ILogger?, string, params object?[])

Unregister a service using the and stop the Application when all services are unregistered.

public void UnregisterAndStop(ILogger? logger, string message, params object?[] args)

26.251.6.9.1. Parameters

logger ILogger?

Logger used to log the success

message string

Message to be logged

args object?[]

Arguments for the log message

26.251.6.9.2. Remarks

If logger is null, the logger of

this
is used.

Triggers the early Cts, and if all the recorded component have stopped, triggers the late Cts and stop the application lifetime.

26.251.6.10. WaitForStartAsync(CancellationToken)

Called at the start of which will wait until it’s complete before continuing. This can be used to delay startup until signaled by an external event.

public Task WaitForStartAsync(CancellationToken cancellationToken)

26.251.6.10.1. Parameters

cancellationToken CancellationToken

Used to abort program start.

26.251.6.10.2. Returns

Task

A .