17.244. 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
17.244.1. Inheritance
17.244.2. Implements
17.244.3. Inherited Members
object.Equals(object?), object.Equals(object?, object?), object.GetHashCode(), object.GetType(), object.MemberwiseClone(), object.ReferenceEquals(object?, object?), object.ToString()
17.244.4. Constructors
17.244.4.1. ExceptionManager(IHostApplicationLifetime, ILogger<ExceptionManager>?, Options?)
Build an ExceptionManager
public ExceptionManager(IHostApplicationLifetime applicationLifetime, ILogger<ExceptionManager>? logger = null, ExceptionManager.Options? options = null)
17.244.4.1.1. Parameters
applicationLifetime IHostApplicationLifetime
The lifetime of the application
logger ILogger<ExceptionManager>?
The logger for the ExceptionManager
options ExceptionManager.Options?
Options for the ExceptionManager
17.244.5. Properties
17.244.5.1. EarlyCancellationToken
CancellationToken that is triggered as soon as the application is stopped, or too many errors were thrown
public CancellationToken EarlyCancellationToken { get; }
17.244.5.1.1. Property Value
17.244.5.2. Failed
Whether there were too many errors
public bool Failed { get; }
17.244.5.2.1. Property Value
17.244.5.3. LateCancellationToken
CancellationToken that is triggered after a grace delay
public CancellationToken LateCancellationToken { get; }
17.244.5.3.1. Property Value
17.244.6. Methods
17.244.6.1. Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
public void Dispose()
17.244.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)
17.244.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
17.244.6.2.2. Remarks
If logger is null, the logger of
this is used.
Following errors are logged as Warnings instead of Errors
17.244.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)
17.244.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
17.244.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
17.244.6.4. RecordSuccess(ILogger?)
Decrease the number of recorded errors to indicate that the application is behaving correctly.
public void RecordSuccess(ILogger? logger = null)
17.244.6.4.1. Parameters
logger ILogger?
Logger used to log the success
17.244.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.
17.244.6.5. Stop(ILogger?, string, params object?[])
Stop the Application without any error
public void Stop(ILogger? logger, string message, params object?[] args)
17.244.6.5.1. Parameters
logger ILogger?
Logger used to log the success
message string
Message to be logged
args object?[]
Arguments for the log message
17.244.6.5.2. Remarks
If logger is null, the logger of
this is used.
The only difference with stopping the application directly is the log message. Using this function indicates the reason of the shutdown, instead of indicating an external shutdown.