Not that I would recommend it, but you can also try something like extension methods on Func.
public static RunAndLog(this Func<T> f) {
LogStart(f);
var x = f();
LogEnd(f);
return x;
}
I think you may have enough diagnostic info with reflection to write something meaningful, and you can add overloads with generic parameters for the func params, and/or Action.
You may also create an IDisposable that logs a start and end statement around a function call:
using var _ = CallLogger(“func name”) {
f();
}
Personally, I wouldn’t do either of these. This level of logging produces an enormous amount of noise, making finding signal very difficult. I would focus more energy on writing unique and helpful messages where they are important, and using git grep
to find the related source code when they show up in production logs (assuming you don’t log a stack trace). This level of call logging can be temporarily useful while debugging or reasoning through an app, but rarely belongs in production.
Douglas Crockford, author of “JavaScript: The Good Parts” has said:
“JavaScript is the only language in the world that people think they write without learning it first.”
I think this is a true statement (well, that and bash).