Visual Studio debug log (e.g. logcat on Android)?

I am trying to debug a C # /. NET program in Visual Studio 2010, but it is time sensitive, so breakpoints ruin it. Therefore, I just want to register certain events and their relative time and watch them as my program.

Does Visual Studio (or C # or .Net) have the ability to write to a log file that Visual Studio can display as a debug window?

When I'm developing Android in Eclipse, I can use their log class and insert lines that look like this in my code:

Log.d("Label1", "Hit checkpoint X"); 

And they will appear along with the time and date stamps in the LogCat window, which is displayed along with other windows in Eclipse.

What is closest to this in Visual Studio 2010?

+7
c # visual-studio
source share
2 answers

You can set a breakpoint that does not actually break, but instead displays a log message. Just set a breakpoint, then right-click on the breakpoint and select "When Hit ...".

In this dialog box, select Print Message and Continue.

Dialog screenshot

+6
source share

Actually, nothing of the kind is built exactly like logcat, but there are many logging frameworks you can use.

Personally, I like to use NLog and configure the UDP target for tracing / debugging in my configuration file, along with the rule, move all the loggers to the target. I think NLog is easier to use than Log4Net (the .NET Log4j port). Once you do this, you can create a logger from the manager and call the logger in the same way as LogCat in android:

 Logger logger = LogManager.GetLogger("MyClassTag"); logger.Trace("Something to log"); logger.Debug("Something to log"); logger.Info("Something to log"); logger.Warn("Something to log"); logger.Error("Something bad to log", exception); logger.Fatal("Something bad to log", exception); 

I use Log2Console to listen on UDP protocol packets, which allows me to view them in the same way as the Android trap viewer.

+2
source share

All Articles