我有一个包含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
}
有关我需要修改WCF以获取SlimDX输出的任何见解?
如果没有指定,则Debug类具有Default Trace Listener。因此,您应该能够在Visual Studio的“输出”窗口中看到该日志。 (Debug-> Windows-> Output)但是,如果处于Release模式,则它不会登录到输出窗口。尝试在调试模式下执行程序或在文件顶部添加“#define DEBUG”然后执行。希望能帮助到你!