4

I'm trying to create a simple logger to check what's happening on the client-side. How can I get the list of locals (as displayed on visual studio while debugging)?

kind of like when a breakpoint is hit, the current existing instances of objects/variables are shown on the Locals tab or should I just get the variable's current value whenever I write on the log?

1 Answer 1

5

Interesting thing...

I usually log all method parameters names and values with a combination of Reflection and runtime data, never thought about also catching local variables values...

here some info:

Accessing Local Variable Information

Sign up to request clarification or add additional context in comments.

3 Comments

I saw the localvariableinfo on msdn before and it doesn't actually return the value, only the type and index number. I might have missed something though. Thanks.
because the metadata available via reflection are generated at compile time and do not contain, ever, runtime values. For that you need some more magic, like for example for the method parameters, I pass the actual values to the logger when I call the logger from the catch block.
I see. Then that means I'll need to pass (or get) the values. I guess this only does half of what I'm expecting and the other half needs to be done manually. Thanks for clearling it up.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.