0

We're currently trying to figure out how to create really extended logging. so including the method call stack, method parameters, values, everything.

to do that we're basically using reflections. we have a factory method creating an instance and then comes the dirty point. we're creating this instance using string concatenated c# code.

the target is to append the logging code before and after the executed function in the context while having access to the type signature

i personally would rather like something like this:

public class LoggingWrapper<T> : T{
    public LoggingWrapper(){
        var virtualMethodsOfT = /* Do Reflection magic here */;
        foreach(var method in virtualMethodsOfT){
            this.CreateOverrideFunction(method.Name, ()=> LoggingOutline(method.BaseCall));
        }
    }

    static LoggingOutline(Action baseMethod){
    // Logging Code before
    baseMethod();
    // Logging Code after
    }
}

to make it look sexy i'd probably also store the reflection data in a in-memory dictionary, because i heard it's awfully slow

  • Why do you want to use reflection? For attaching logger to functions or attach code to logger? Could you describe your purpose more descriptive? – Leszek Mazur Sep 18 '21 at 07:03
  • i tried^^ all i want is to apply custom logging at the beginning and at the end of a function. i want to log the method signature like name, parameters including the parameters it has been called with. reason: error logging. a lot of exceptions have no possibility to figure out what exactly went wrong. if the method grows too long and you have a null reference exception and the method has 20 parametrs (worst case), then it's impossible to find out what actually happened. btw it should be a replacement for fody... because we're using that a.t.m – Kyoshiro Kokujou Obscuritas Sep 18 '21 at 07:06
  • the important point is that i want to have the same code in every service i'm injecting. without needing to plug it manually in every method. this is why i want to have some kind of "wrapper" which overrides the function and adds code before and after. – Kyoshiro Kokujou Obscuritas Sep 18 '21 at 07:07

0 Answers0