Reputation: 4399
I have a class representing the current settings of the software that I'm developing and what I'd like to do is to get the values of all properties and fields in an instance of that class during a debug breakpoint. I know you can hover on the instance and get that information, but I can't find a way to dump it to a file or see it in a separate window. Is there a way to do it in Visual Studio 2010? (I'm using C#.)
Upvotes: 0
Views: 506
Reputation: 9566
You can use Trace.Writeline but you can use logging too on production.
You can write some code like:
internal class Log {
public void Write(string format, params object [] args) {
File.AppendAllText(@".\log.txt", string.Format(@"{0}, {1}", DateTime.Now, string.Format(format, args)));
}
}
on your code
...
Log.Write("Starting program");
...
Log.Write("Config value \"{0}\".", Config.Value);
...
Log.Write("Processing data code {0} {1} times.", code, times);
...
Upvotes: 1
Reputation: 4572
There are several ways to do this.
1.) open your locals window and you maybe able to see the variable there. If it is nested in some other object you will need to expand the variable to see it.
2.) you could open a watch window and put the variable in there to see its contents.
3.) you could use the immediate window and execute a Trace.Writeline(...) of the variable to see it in the output.
Upvotes: 1