views:

822

answers:

3

I am trying to log a method's parameters by using reflection. I read the earlier question posted about this issue on StackOverflow as well which pointed me to CLR API's.

Is it possible, someone can point me to the right direction, as to how will I get the values of parameters passed using API?

+2  A: 

Basically you can't in "vanilla" .NET code. Parameters are just local variables, and their values can't be fetched without delving into the debugger API mentioned in the other thread.

What you may be able to do is use PostSharp to insert the logging code. I'd suggest going that route before looking at the debugging API!

Jon Skeet
I do not think I can modify much of the code architecture. Is it possible to inject this framework just to get the parameters logged>
Syed Sajid Nizami
+1  A: 

If you're feeling adventurous you could look at the RealProxy class in System.Runtime.Remoting.Messaging. It allows you to implement a proxy class which can intercept calls to your methods. You could then log out the parameters and forward the call onto your actual class.

There'll be a performance hit for this, but it'll probably give you what you're looking for...

Sean
A: 

@ Sean: This seems promising, Is it possible to intercept and get values like that in WCF? I know the service log already contains that information but it is difficult to dig through it which makes me look for alternative ways to log methods and their parameters.

Syed Sajid Nizami