可以在Visual Studio的输出窗口中查看OutputDebugString的输出? [英] Can output from OutputDebugString be viewed in Visual Studio's output window?

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

问题描述



当我使用 OutputDebugString 编写调试信息时,我正在使用C#和Visual  Studio。 ,是否会在输出窗口中显示?



我可以在 OutputDebugString https://technet.microsoft.com/en-us/sysinternals/debugview.aspx =nofollow noreferrer> DebugView ,但我以为我会在Visual Studio的输出窗口中看到它。我在菜单工具中看过
选项?调试? 一般,并且输出不被重定向到立即窗口。我还看过菜单工具*? 选项?调试?输出窗口和所有常规输出设置设置为开。最后,我使用输出窗口中的下拉列表来指定调试消息应该出现。



如果我更改菜单工具*? 选项?调试? 将输出重定向到立即窗口, OutputDebugString 消息不会出现在即时窗口中。



这是我的整个测试程序:

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

命名空间OutputDebugString
{
类程序
{
[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 输出。



如果我从控制台窗口运行,那么 Debug.WriteLine OutputDebugString 显示在DebugView中。



为什么输出窗口中没有出现 OutputDebugString 输出?



最终,我的目的不是用 OutputDebugString 编写大量调试输出,而是使用System。诊断或NLog或类似的东西。我只是试图找出,如果我配置一个日志记录平台来写入 OutputDebugString ,输出将在调试器中可见。



我回到我原来的程序(不是上面的简单测试),它使用 TraceSources TraceListeners 通过 app.config 文件配置。如果我将跟踪源配置为写入 System.Diagnostics.DefaultTraceListener (以文字形式写入 OutputDebugString ) ,则跟踪源输出DOES进入调试窗口。但是,直接使用 OutputDebugString (例如在我的简单示例中)直接写入的行不要去调试窗口。另外,如果我使用不同的 TraceListener 写入 OutputDebugString (我在Codeplex的Ukadc.Diagnostics中有一个),该输出不会进入调试窗口。



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



请注意,我已经看到这些问题,但没有提供一个可行的解决方案:



此处此处

解决方案

你有我在这个问题上一段时间。没门!



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


I am using C# and Visual Studio 2010.

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 menu Tools ? Options ? Debugging ? General, and the output is NOT being redirected to the Immediate window. I have also looked under menu 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.

If I change menu 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");
    }
  }
}

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

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

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

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.

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.

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 I 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".

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

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