可以从OutputDebugString的输出VisualStudio中的输出窗口中查看 [英] Can output from OutputDebugString be viewed in VisualStudio's output window

查看:559
本文介绍了可以从OutputDebugString的输出VisualStudio中的输出窗口中查看的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用C#和Visual Studio 2010。

I am using C# and VS2010.

当我使用的OutputDebugString写调试信息,它应该显示在输出窗口?我可以看到输出从DebugView中OutputDebugString的,但我想我会看到它在Visual Studio中的输出窗口。我已经在工具 - >选项 - > Debugging->常规望去,输出不被重定向到立即窗口。我也下工具 - >选项 - > Debugging->输出窗口望去,所有的通用输出设置被设置为开。最后,我已经使用了下拉列表中的输出窗口,以指定调试信息就会显示出来。

When I use OutputDebugString to write debug information, should it show up in the output window? I can see the output from OutputDebugString in DebugView, but I thought I would see it in Visual Studio's Output window. I have looked under Tools->Options->Debugging->General and the output is NOT being redirected to the Immediate window. I have also looked under Tools->Options->Debugging->Output Window and all General Output Settings are set to "On". Finally, I have used the drop-down list in the Output window to specify that Debug messages should appear.

如果我更改工具 - >选项 - > Debugging->常规,将输出重定向到立即窗口中,OutputDebugString的信息不会出现在眼前的窗口

If I change Tools->Options->Debugging->General to redirect the output to the Immediate window, the OutputDebugString messages do not appear in the immediate window.

下面是我的整个测试程序:

Here is my entire test program:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using System.Diagnostics;

namespace OutputDebugString
{
  class Program
  {
    [DllImport("kernel32.dll", CharSet = CharSet.Auto)]
    public static extern void OutputDebugString(string message);

    static void Main(string[] args)
    {
      Console.WriteLine("Main - Enter - Console.WriteLine");
      Debug.WriteLine("Main - Enter - Debug.WriteLine");
      OutputDebugString("Main - Enter - OutputDebugString");
      OutputDebugString("Main - Exit - OutputDebugString");
      Debug.WriteLine("Main - Exit - Debug.WriteLine");
      Console.WriteLine("Main - Exit - Console.WriteLine");
    }
  }
}

如果我在调试器中运行,中的Debug.WriteLine输出确实在输出窗口中显示出来,但是OutputDebugString的不输出。

If I run within the debugger, the Debug.WriteLine output does show up in the output window, but the OutputDebugString output does not.

如果我从一个控制台窗口中运行,无论是和的Debug.WriteLine OutputDebugString的在DebugView中显示出来。

If I run from a console window, both Debug.WriteLine and OutputDebugString show up in DebugView.

为什么不OutputDebugString的产量曾经在输出窗口中显示?

Why doesn't the OutputDebugString output ever show up in the output window?

最终,我的意图是不是写了很多调试输出与OutputDebugString的,而我会用System.Diagnostics程序或NLOG或类似的东西。 。我只是试图找出,如果我配置日志平台,写信给OutputDebugString的,将输出从调试器中可见

Ultimately, my intent is not to write a lot of debug output with OutputDebugString, rather I will use System.Diagnostics or NLog or something similar. I am just trying to find out, if I configure a logging platform to write to OutputDebugString, will the output be visible from within the debugger.

编辑:
我回到它采用通过app.config文件配置TraceSources和TraceListeners我原来的程序(不高于简单的测试)。如果我配置跟踪源写入System.Diagnostics.DefaultTraceListener(被记录为写入OutputDebugString的),然后跟踪源输出不会去调试窗口。然而,直接与OutputDebugString的(如在我简单的例子),该写行不要去调试窗口。另外,如果我使用不同的TraceListener写入到OutputDebugString的(我得到了一个从CodePlex上Ukadc.Diagnostics),即输出不会去调试窗口。

I went back to my original program (not the simple test above) which uses TraceSources and TraceListeners configured via the app.config file. If I configure the trace sources to write to the System.Diagnostics.DefaultTraceListener (which is documented as writing to OutputDebugString), then the trace source output DOES go to the debug window. However, lines that write directly with OutputDebugString (such as in my simple example) DO NOT go to the debug window. Also, if I use a different TraceListener that writes to OutputDebugString (I got one from Ukadc.Diagnostics at codeplex), that output DOES NOT go to the debug window.

一注意有关Ukadc.Diagnostics跟踪侦听... Ukadc.Diagnostics包含一些跟踪侦听器,使输出的自定义格式(类似于在log4net的,NLOG可用的格式和LAB)。所以,用只有在Ukadc.Diagnostics我们可以使用标准.NET诊断日志,但是可以得到一些高级功能(如输出格式),而不成为依赖于可能更大平台的依赖。在这种情况下,我可以使用Ukadc.Diagnostics OutputDebugStringTraceListener写在相同的格式记录输出到调试窗口(如果需要的话,或不同的格式),因为它是,如果写入文件

One note about the Ukadc.Diagnostics trace listener... Ukadc.Diagnostics contains some trace listeners that allow for custom formatting of output (similar to the formatting that is available in log4net, NLog, and LAB). So, with "only" a dependency on Ukadc.Diagnostics one can use "standard" .NET diagnostic logging but can get some advanced features (like the output formatting) without becoming dependent on a possibly much larger platform. In this case, I could use the Ukadc.Diagnostics OutputDebugStringTraceListener to write logging output to the debug window in the same format (if desired, or a different format) as it would be if written to a file.

请注意,我已经看到了这些问题,但他们没有提供一个有效的解决方案:
这里和的这里

Note that I have seen these questions but they did not provide a working solution: here and here

推荐答案

您已让我相信在这个问题上一会儿。没门!方式。

You had me going on this question for a while. No way! Way.

项目+属性,调试选项卡,勾选启用非托管代码调试。

Project + Properties, Debug tab, check "Enable unmanaged code debugging".

这篇关于可以从OutputDebugString的输出VisualStudio中的输出窗口中查看的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆