-1

In a project I don't want to use breakpoints to view variable values so I use:

Debug.WriteLine("This is a test.", "SomeIdentifier");

Where Debug is from "System.Diagnostics" and "this is a test." is replaced with some variable value. Now when I look in the debug output window I see a very large list, I can make the list smaller by only showing ProgramOutput in this window (right click in output window -> program output). However There is still a large list while I only want to look at the value of same variable which has a specific identifier like "SomeIdentifier". I could use ctrl+f to search for the items instead of looking for them and save a bit of time but it's still not effective. for example the following situation:

Im running a large number of calls on my asp.net application for a stress test and want to see if a specific variable is valid, and only that specific variable. I just want to see a list of that value only for example.

SomeIdentifier - 1
SomeIdentifier - 2
SomeIdentifier - 3
SomeIdentifier - 4

instead of:

SomeIdentifier - 1
some other stuff    some other stuff    some other stuff
some other stuff    some other stuff
some other stuff           some other stuff 
SomeIdentifier - 2
some other stuff    some other stuff    some other stuff
SomeIdentifier - 3
some other stuff    some other stuff
some other stuff    some other stuff    some other stuff
some other stuff    some other stuff
some other stuff
some other stuff
SomeIdentifier - 4

I could write to a log file but that sound not very efficient (need to add even more code/dependecy to log framework to log a variable). Is it possible to debug a specific variable without using breakpoints or having to search a list/create a log file?

note: im using C#

Sven van den Boogaart
  • 11,833
  • 21
  • 86
  • 169
  • `I could write a log function but that sound not very effective.` - Why do you say that? You could use an existing logging framework (like log4net or similar) and set the logging level of everything else to 'debug', and this to 'info', then just log at info level which will only list your info output. You can log to a console, or to a logfile or whatever really. – Jay May 30 '17 at 08:22
  • @Jay I ment " I could write to a log file" that would mean i needed to open the file to look at the values dosnt sound very effective, i assumed there is a built in function for visual studio to watch a variables value without breaking the programming. Thanks for the suggestion of using a logging framework will look into log4net. – Sven van den Boogaart May 30 '17 at 08:29
  • If I have understood your request, you could use `Console.Write(your_variable)` - It will show the output on the console output window in Visual Studio. – Simone Cifani May 30 '17 at 08:31
  • @SimoneCifani an asp.net program as given in the example does not have a console. – Sven van den Boogaart May 30 '17 at 08:32
  • @SvenB What example? – Simone Cifani May 30 '17 at 08:33
  • @SimoneCifani "Im running a large number of calls on > my asp.net application < for a stress test and want to see if a specific variable is valid" – Sven van den Boogaart May 30 '17 at 08:33
  • @SvenB My apologies. In this case [Assert](https://msdn.microsoft.com/en-us/library/ms182530.aspx) could be an option – Simone Cifani May 30 '17 at 08:38
  • @SimoneCifani could you give an example? I only know assert of a unit test method im not sure how that answers my question. – Sven van den Boogaart May 30 '17 at 08:54
  • @SvenB In your example `some other stuff` represents the messages shown by default on the program output? In this case I have completely misunderstood the question and you simply have to disable them from VS, as shown in [this post](https://stackoverflow.com/questions/14720599/disable-noise-messages-in-debug-output-windows-visual-studio-2012). – Simone Cifani May 30 '17 at 09:15
  • @SimoneCifani yes some other stuff represents other message. I already did what is posted in the question you linked see : " I can make the list smaller by only showing ProgramOutput in this window (right click in output window -> program output)" – Sven van den Boogaart May 30 '17 at 09:19
  • @SvenB My last attempt: [ASP .Net Trace](https://msdn.microsoft.com/en-us/library/bb386420.aspx) – Simone Cifani May 30 '17 at 09:42
  • @SimoneCifani please provide an example, i red the article but dont understand how it would answer my question. – Sven van den Boogaart May 30 '17 at 11:12

1 Answers1

-1

I just tested what suggested in this post:

Right click on the Output window for the Debug selection; here you can select which types of messages to see.

Uncheck all except for Program Output

It works for me, this is my test under VS 2013:

enter image description here

Simone Cifani
  • 784
  • 4
  • 14
  • thanks for the help, thats what i did as stated in the question, if your working with threads program output will contain for example: The thread 0x29c0 has exited with code 0 (0x0). The thread 0x3308 has exited with code 0 (0x0). The thread 0x7f0 has exited with code 0 (0x0). The thread 0xf74 has exited with code 0 (0x0). or if your working with telemetry Application Insights Telemetry (unconfigured): {"name":"Microsoft.ApplicationInsights.Metric","time":"2017-05-30T12:40:50.5749335Z","tags. – Sven van den Boogaart May 30 '17 at 12:48