It's certainly possible. You could use the Action and Func delegates.
TReturn RunWithLog<T, TResult>(ILogger logger, Func<T, TResult> function, T parameter1)
{
logger.LogInformation(....);
return function(parameter1);
}
void RunWithLog<T>(ILogger logger, Action<T> function, T parameter1)
{
logger.LogInformation(....);
function(parameter1);
}
You'd need to implement one for each number of parameters you want to accept.
You could also return a new func or action that contains the code in those methods to be called repeatedly. But I don't think there'd be any advantage to doing it that way. I guess you could then pass it as an argument.
Action<T> BuildRunWithLog<T>(ILogger logger, Action<T> function)
{
return (T parameter1) =>
{
logger.LogInformation(....);
function(parameter1);
}
}
Wrote that from memory so syntax may be wrong.