简体   繁体   English

如何在Visual Studio中查找哪些代码输出某些调试字符串?

[英]How to find which code outputs certain debug string in Visual Studio?

Is there a way to find out which piece of code does certain prints in the Output window in Visual Studio? 有没有一种方法可以找出某些代码在Visual Studio的“输出”窗口中打印出来了?

I have very large project which outputs bunch of small prints repeatedly in thousands. 我有一个非常大的项目,可以重复输出成千上万的小版画。 It might take days to find where is it because it doesn't have a constant string to do a simple text search in code. 可能需要几天的时间才能找到它的位置,因为它没有常量字符串可以在代码中进行简单的文本搜索。 It seems the output is dynamic (like a property name).. 似乎输出是动态的(如属性名称)。

And it is real-time app. 它是实时应用程序。 Really difficult to debug cos its just goes haywire if you pause it for a second.. 如果暂停一秒钟,调试它真的很困难,因为它只是一团糟。

Any way it can be done (other than eyeballing 1000s of debug statements)? 有什么办法可以做到(除了盯着1000条调试语句)?

I'm assuming that your app is generating these prints using System.Diagnostics.Debug or .Trace calls. 我假设您的应用正在使用System.Diagnostics.Debug或.Trace调用生成这些打印。 In that case you can write a TraceListener and add it to the Debug.Listeners collection. 在这种情况下,您可以编写一个TraceListener并将其添加到Debug.Listeners集合中。 You then have your own handler for the prints and can likely filter your dynamic output (or set a conditional breakpoint). 然后,您将拥有自己的打印处理程序,并且可能会过滤动态输出(或设置条件断点)。 If that's not sufficient you can use System.Diagnostics.StackTrace within your handler to print calling functions real-time. 如果这还不够,您可以在处理程序中使用System.Diagnostics.StackTrace实时打印调用函数。

You can try my Runtime Flow tool (30-day trial). 您可以尝试运行时流程工具(30天试用版)。 Set filter to include your code and the debug output method, start monitoring and capture debug output calls, search for your certain debug string as the parameter to the debug output method in the Flow window, see what calls this output method. 设置过滤器以包括您的代码和调试输出方法,开始监视和捕获调试输出调用,在“流程”窗口中搜索某些调试字符串作为调试输出方法的参数,看看调用该输出方法的内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM