【问题标题】:Capture System.Diagnostics.Debug Output in a WCF application在 WCF 应用程序中捕获 System.Diagnostics.Debug 输出
【发布时间】:2017-12-30 02:23:40
【问题描述】:

我有一个包含 SlimDX 库的 WCF 控制台应用程序。 SlimDX 使用 System.Diagnostics.Debug 的 'Write' 方法输出日志。我目前无法在控制台中查看此日志。我想捕获 SlimDX 的输出并将其写入控制台。

这是我目前的实现(不工作):

FileStream fs = new FileStream("C:/users/paulm/documents/output.txt", FileMode.Create);

            Writer = new StreamWriter(fs);
            System.Diagnostics.Debug.Listeners.Add(new System.Diagnostics.TextWriterTraceListener(Writer));

此实现未捕获 SlimDX 的输出。这里是 SlimDX 源代码:

#include "ObjectTable.h"

#include "InternalHelpers.h"

#include "ComObject.h"



using namespace System;

using namespace System::Text;

using namespace System::Threading;

using namespace System::Globalization;

using namespace System::Collections::ObjectModel;

using namespace System::Collections::Generic;

using namespace System::Diagnostics;



namespace SlimDX

{

    static ObjectTable::ObjectTable()

    {

        m_Table = gcnew Dictionary<IntPtr, ComObject^>();

        m_Ancillary = gcnew Dictionary<IntPtr, List<ComObject^>^>();

        m_SyncObject = gcnew Object();



        AppDomain::CurrentDomain->DomainUnload += gcnew System::EventHandler( OnExit );

        AppDomain::CurrentDomain->ProcessExit += gcnew System::EventHandler( OnExit );

    }



    ObjectTable::ObjectTable()

    {

    }



    void ObjectTable::OnExit( Object^ sender, EventArgs^ e )

    {

        SLIMDX_UNREFERENCED_PARAMETER(sender);

        SLIMDX_UNREFERENCED_PARAMETER(e);



        String^ leakString = ReportLeaks();

        Debug::Write( leakString ); // this is the output I would like to capture

    }

关于我需要修改 wrt WCF 以捕获 SlimDX 输出的任何见解?

【问题讨论】:

    标签: c# wcf debugging slimdx


    【解决方案1】:

    如果未指定,调试类有一个默认跟踪侦听器。因此,您应该能够在 Visual Studio 的输出窗口中看到日志。 (调试->Windows->输出) 但是,如果您处于发布模式,则它不会记录到输出窗口。尝试在调试模式下执行程序或在文件顶部添加“#define DEBUG”,然后执行。 希望对您有所帮助!

    【讨论】:

      猜你喜欢
      • 2011-09-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-08-30
      相关资源
      最近更新 更多