Skip to content

Class TaskExtensions

Namespace: Void.Proxy.Api.Extensions
Assembly: Void.Proxy.Api.dll

public static class TaskExtensions

Inheritance

objectTaskExtensions

Inherited Members

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

Methods

CatchExceptions(Task, ILogger, string)

Attaches a continuation that logs failures or cancellations from task and returns the continuation task.

public static Task CatchExceptions(this Task task, ILogger logger, string message)

Parameters

task Task

The task to observe for non-successful completion.

logger ILogger

The logger used to emit error messages.

message string

A message prefix included in each error log entry.

Returns

Task

A continuation task that completes after any required logging for task has finished.

Examples

_ = backgroundTask.CatchExceptions(logger, "Background processing failed");

Remarks

The continuation is registered with , so it runs only when the antecedent task faults or is canceled.

For faulted tasks, this method logs completedTask.Exception.InnerException (the first inner exception from the task's ). For canceled tasks, it calls to materialize , then logs that exception together with the call-site stack trace captured when this method was invoked.

The returned represents only the logging continuation, not the original task result. Because it does not rethrow antecedent failures, awaiting the returned task usually completes successfully unless logging itself throws.

See Also

Task.ContinueWith(Action<Task>, TaskContinuationOptions), TaskExtensions.CatchExceptions(ValueTask, ILogger, string)

CatchExceptions(ValueTask, ILogger, string)

Converts task to and applies .

public static ValueTask CatchExceptions(this ValueTask task, ILogger logger, string message)

Parameters

task ValueTask

The value task to observe for non-successful completion.

logger ILogger

The logger used to emit error messages.

message string

A message prefix included in each error log entry.

Returns

ValueTask

A wrapping the logging continuation produced from task.

Examples

await valueTask.CatchExceptions(logger, "Link stop handler failed");

Remarks

This overload delegates all logging behavior and error-handling semantics to .

The returned wraps the continuation task created for logging. As a result, awaiting it waits for logging completion rather than rethrowing the original failure from task.

See Also

ValueTask.AsTask()