Class VhInvoker
Provides the means to run what may fail without letting the failure out: it is logged as
Could not {actionName}. at the level the caller gives.
public static class VhInvoker
- Inheritance
-
VhInvoker
- Inherited Members
Remarks
Give Debug for best-effort work, Warning for what a failure leaves behind, and Error for a bug, such as a failed handler. Every exception is caught; a cancellation is logged at Debug with its own wording. A failure of the log itself is not caught.
Methods
TryInvoke(string, LogLevel, Action)
Runs an action, and logs a failure instead of throwing it.
public static void TryInvoke(string actionName, LogLevel failureLevel, Action action)
Parameters
actionNamestringWhat is being done, for the log line
Could not {actionName}.failureLevelLogLevelThe level a failure is logged at; a cancellation is logged at Debug.
actionActionThe action.
TryInvokeAsync(string, LogLevel, Func<Task>)
Runs an asynchronous action, and logs a failure instead of throwing it.
public static Task TryInvokeAsync(string actionName, LogLevel failureLevel, Func<Task> task)
Parameters
actionNamestringWhat is being done, for the log line
Could not {actionName}.failureLevelLogLevelThe level a failure is logged at; a cancellation is logged at Debug.
taskFunc<Task>Starts the action.
Returns
- Task
A task that completes when the action does, failed or not.
TryInvokeAsync(string, LogLevel, Func<ValueTask>)
Runs an asynchronous action, and logs a failure instead of throwing it.
public static Task TryInvokeAsync(string actionName, LogLevel failureLevel, Func<ValueTask> task)
Parameters
actionNamestringWhat is being done, for the log line
Could not {actionName}.failureLevelLogLevelThe level a failure is logged at; a cancellation is logged at Debug.
taskFunc<ValueTask>Starts the action.
Returns
- Task
A task that completes when the action does, failed or not.
TryInvokeAsync<T>(string, LogLevel, Func<Task<T>>, T?)
Runs an asynchronous function, and logs a failure instead of throwing it.
public static Task<T?> TryInvokeAsync<T>(string actionName, LogLevel failureLevel, Func<Task<T>> task, T? defaultValue = default)
Parameters
actionNamestringWhat is being done, for the log line
Could not {actionName}.failureLevelLogLevelThe level a failure is logged at; a cancellation is logged at Debug.
taskFunc<Task<T>>Starts the function.
defaultValueTThe result after a failure.
Returns
- Task<T>
A task whose result is the function's, or
defaultValueafter a failure.
Type Parameters
TThe type of the result.
TryInvokeAsync<T>(string, LogLevel, Func<ValueTask<T>>, T?)
Runs an asynchronous function, and logs a failure instead of throwing it.
public static ValueTask<T?> TryInvokeAsync<T>(string actionName, LogLevel failureLevel, Func<ValueTask<T>> task, T? defaultValue = default)
Parameters
actionNamestringWhat is being done, for the log line
Could not {actionName}.failureLevelLogLevelThe level a failure is logged at; a cancellation is logged at Debug.
taskFunc<ValueTask<T>>Starts the function.
defaultValueTThe result after a failure.
Returns
- ValueTask<T>
A task whose result is the function's, or
defaultValueafter a failure.
Type Parameters
TThe type of the result.
TryInvoke<T>(string, LogLevel, Func<T>, T?)
Runs a function, and logs a failure instead of throwing it.
public static T? TryInvoke<T>(string actionName, LogLevel failureLevel, Func<T> func, T? defaultValue = default)
Parameters
actionNamestringWhat is being done, for the log line
Could not {actionName}.failureLevelLogLevelThe level a failure is logged at; a cancellation is logged at Debug.
funcFunc<T>The function.
defaultValueTThe result after a failure.
Returns
- T
The function's result, or
defaultValueafter a failure.
Type Parameters
TThe type of the result.