捕获System.Diagnostics.Debug WCF应用程序中的输出

时间:2017-12-30 02:23:41

标签: c# wcf debugging slimdx

我有一个包含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

    }

关于为了捕获SlimDX输出而需要修改WCF所需的任何见解?

1 个答案:

答案 0 :(得分:0)

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