Class ResultLoggingExtensions

Namespace
REslava.Result.Extensions
Assembly
REslava.Result.dll

Extension methods for logging Result outcome to ILogger.

public static class ResultLoggingExtensions
Inheritance
ResultLoggingExtensions
Inherited Members

Methods

LogOnFailure<T>(Task<Result<T>>, ILogger, string, CancellationToken)

Awaits the result task, logs only on failure, and returns the result unchanged (Tap-style). Failure without exception → Warning; failure wrapping ExceptionErrorError. Success produces no log output.

public static Task<Result<T>> LogOnFailure<T>(this Task<Result<T>> resultTask, ILogger logger, string operationName, CancellationToken cancellationToken = default)

Parameters

resultTask Task<Result<T>>

The result task to await.

logger ILogger

The logger to write to.

operationName string

Name of the operation — appears in every log message.

cancellationToken CancellationToken

Optional cancellation token.

Returns

Task<Result<T>>

The original result, unchanged.

Type Parameters

T

The result value type.

Examples

Result<Order> result = await service.PlaceOrder(request)
    .LogOnFailure(logger, "PlaceOrder");

WithLogger<T>(Task<Result<T>>, ILogger, string, CancellationToken)

Awaits the result task, logs the outcome to logger, and returns the result unchanged (Tap-style). Success → Debug; failure without exception → Warning; failure wrapping ExceptionErrorError.

public static Task<Result<T>> WithLogger<T>(this Task<Result<T>> resultTask, ILogger logger, string operationName, CancellationToken cancellationToken = default)

Parameters

resultTask Task<Result<T>>

The result task to await.

logger ILogger

The logger to write to.

operationName string

Name of the operation — appears in every log message.

cancellationToken CancellationToken

Optional cancellation token.

Returns

Task<Result<T>>

The original result, unchanged.

Type Parameters

T

The result value type.

Examples

Result<User> result = await service.GetUser(id)
    .WithLogger(logger, "GetUser");