S
ssg31415926
Is there any way to get the name of the method that called the current
method?
Also, is there any way to get the values of the parameters passed into
the method, along with the parameter names?
I want to write a method that I can call at the start of each method
for logging purposes.
It'll check if the logging level is high enough, and if so, record the
method name and each parameter name and value.
I realise I can use reflection to get the name of the current method
and the names of the parameters. How can I get the name of the method
that called the current method? Or is the only way to do this to pass
System.Reflection.MethodBase.GetCurrentMethod() as a parameter?
And how can I get the values of the parameters? I was hoping there'd
be a Key-Value collection containing them but can't find anything.
Failing that, is there a way to say 'give me the value of the
parameter named in this string'?
method?
Also, is there any way to get the values of the parameters passed into
the method, along with the parameter names?
I want to write a method that I can call at the start of each method
for logging purposes.
It'll check if the logging level is high enough, and if so, record the
method name and each parameter name and value.
I realise I can use reflection to get the name of the current method
and the names of the parameters. How can I get the name of the method
that called the current method? Or is the only way to do this to pass
System.Reflection.MethodBase.GetCurrentMethod() as a parameter?
And how can I get the values of the parameters? I was hoping there'd
be a Key-Value collection containing them but can't find anything.
Failing that, is there a way to say 'give me the value of the
parameter named in this string'?