antlersoft
antlersoft

Reputation: 14786

How to write to Visual Studio 2010 debug output window from Silverlight?

I am trying to get my Silverlight application to write to the Output/Debug window in Visual Studio 2010.

I've tried System.Diagnostics.Debug.WriteLine, and System.Diagnostics.Debugger.Log, both of which seem to promise to write output to this window when the VS 2010 debugger is attached to the process.

I attach VS 2010 to the iexplore.exe hosting the Silverlight app in Silverlight mode, but I have yet to see any of the output I am trying to log. I do see log messages for other things happening in the application; exceptions thrown, modules loaded, thread deaths, binding errors. What do I need to do in the Silverlight app to log to the same place?

I guess my alternative is to log to a global StringBuilder and break the process in the debugger and examine that, but that is much less convenient than looking at the information as it is logged in real time.

Upvotes: 5

Views: 13831

Answers (1)

McAden
McAden

Reputation: 13972

System.Diagnostics.Debug.WriteLine does indeed do what you're asking. I would check several things.

Make sure:

  1. You're attached to the right iexplore.exe process. Multiple iexplore.exe processes are launched, not just one.
  2. Your host project is set to debug Silverlight. This is an option in the project properties of the host project.
  3. If you set a breakpoint in your code that it does indeed break - if the code runs but the breakpoint isn't hit then you've attached using the wrong version of the code.
  4. "Show output from:" in the output window of visual studio is set to "Debug"
  5. If you right-click in the Output Window, ensure that "Program Output" is checked in addition to the other messages.

Upvotes: 7

Related Questions