开发者

Visual-Studio Output window events time

When i u开发者_JAVA技巧se Trace methods (.NET) to see what happening in my code i need to add time to output string in most cases. Thats allow me to see when actually output string was printed. Is there any way to customize IDE (probably, some options or extensions) so time will be added automatically?


There is a set of Visual Studio extensions called Productivity Power Tools available for VS2010 right the way to VS2017. One of the features from 2013 onwards is "Timestamp Margin" which adds a timestamp at the start of each line in the Debug Output Window only. Features in the extension can be enabled individually.

If you're using VS2017, there is also a much more lightweight, standalone extension with just the one feature.

Finally, there is also a much fancier extension called VSColorOutput which colour codes the Debug Output Window based on regular expressions. Optionally it will add timestamps as well.

At the time of writing all of these options work only on the Debug output.

I know this question is tagged with VS2010 but I think anyone reading this still using that version will be in the minority.


Depending on which trace methods you are using, and how picky you are about format, you may not need to write additional code.

You can set the Timestamp or DateTime TraceOption flag on your trace listener's TraceOutputOptions property. You can set that property programmatically or via your configuration file.

The DateTime flag with the default trace listener gives you something that looks like this:

prog1.vshost.exe Information: 0 : Hello world DateTime=2011-03-12T22:22:55.6902126Z

while Timestamp looks like this:

prog1.vshost.exe Information: 0 : Hello world Timestamp=991294310087

See the remarks section of the TraceOutputOptions documentation for caveats - e.g., the flags don't affect Write() and WriteLine().


That requires code. In your program. It isn't hard code, works without the debugger too. Which tends to be important if you care about time.

Look at, say, log4net to get this added automatically.


You should be able to write a little function like wchar_t * GetCurrTimestamp() and stick it in your TRACE macro calls, like this:

TRACE(_T("%s: My debug message.\r\n"), GetCurrTimestamp() );
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜