I have been spending a lot of time trying to find a library that allows to log information about the methods that are being executed. Somehow I feel that all of them are too invasive. Is there any library or code that makes this so simple that I only need to add a decorator/attribute to the method?
Here what I would like to have:
internal class Calculator
{
[CustomInterceptor]
public static int Add(int a, int b)
{
return a + b;
}
}
internal class CustomInterceptor : Attribute
{
//here some implementation
}
static void Main(string[] args)
{
var result = Calculator.Add(10, 2);
Console.WriteLine($"Result : {result}");
}
Desired output
Before Add
Result 12
After Add
If this can be done with Reflection, please I would prefer that approach since that would imply no need for third party libraries.
Thanks in advance.
Aucun commentaire:
Enregistrer un commentaire