![](/img/trans.png)
[英]Using System.Diagnostics.Debug In An ASP.NET Application
[英]Capture System.Diagnostics.Debug Output in a WCF application
我有一个包含SlimDX库的WCF控制台应用程序。 SlimDX使用System.Diagnostics.Debug的“写入”方法输出日志。 我目前无法在控制台中查看此日志。 我想捕获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输出的任何见解?
如果未指定,则Debug类具有默认跟踪侦听器。 因此,您应该能够在Visual Studio的“输出”窗口中查看日志。 (调试-> Windows->输出)但是,如果您处于发布模式,则它将不会登录到输出窗口。 尝试以“调试”模式执行程序,或在文件顶部添加“ #define DEBUG”,然后执行。 希望能帮助到你!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.