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 ExceptionError → Error. 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
resultTaskTask<Result<T>>The result task to await.
loggerILoggerThe logger to write to.
operationNamestringName of the operation — appears in every log message.
cancellationTokenCancellationTokenOptional cancellation token.
Returns
Type Parameters
TThe 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 ExceptionError → Error.
public static Task<Result<T>> WithLogger<T>(this Task<Result<T>> resultTask, ILogger logger, string operationName, CancellationToken cancellationToken = default)
Parameters
resultTaskTask<Result<T>>The result task to await.
loggerILoggerThe logger to write to.
operationNamestringName of the operation — appears in every log message.
cancellationTokenCancellationTokenOptional cancellation token.
Returns
Type Parameters
TThe result value type.
Examples
Result<User> result = await service.GetUser(id)
.WithLogger(logger, "GetUser");