Reputation: 477
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?
Upvotes: 2
Views: 1380
Reputation: 1500495
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!
Upvotes: 3
Reputation: 477
@ 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.
Upvotes: 0
Reputation: 62472
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...
Upvotes: 1