[英]How to write to OutputDebugString from ASP.net web-site?
我需要從網站上的代碼輸出一些調試信息。
如何從ASP.net網站調用OutputDebugString
, 並使它顯示給運行DbgView的用戶 ?
注意 :網站不支持System.Diagnostics.Trace.TraceWarning(...)
。
好的,這是一個完整的示例。 它是一個控制台,但是原理和代碼是相同的。 我今天無法測試從我的計算機上的OutputDebugString捕獲,因為我沒有管理員權限。 在服務器上,您要寫入TextWriterTraceListener而不是控制台。 如果您無法使用pinvoke進行OutputDebugString的寫入和讀取,則可能是客戶沒有權利或應用程序沒有必要的權利。
也! 如果未顯示Debug.WriteLine,則可能是網站已在RELEASE模式下編譯,並且未定義DEBUG。 默認情況下,TRACE是為RELEASE And DEBUG定義的。 除非您清除了默認的偵聽器,否則TraceSource會寫入OutputDebugString,這是很多人的習慣,因為根據我的經驗,如果您現在不實際查看輸出,則OutputDebugString會使速度變慢,尤其是。
using System.Diagnostics;
using System.Runtime.InteropServices;
namespace TraceToOutputDebugString
{
class Program
{
[DllImport("kernel32.dll")]
static extern void OutputDebugString(string lpOutputString);
static void Main(string[] args)
{
//Put these lines in your asp.net Page
OutputDebugString("Hello from Pinvoke OutputDebugString");
TraceSource trace = new TraceSource("app");
trace.TraceInformation("Hello from TraceSource");
Trace.TraceInformation("Hello from 1.1 Trace.TraceInformation");
Debug.WriteLine("Hello Debug.WriteLine");
System.Console.ReadKey();
}
}
}
這是配置。
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.diagnostics>
<sources>
<source name="app" switchName="app">
<listeners>
<add name="Console" type="System.Diagnostics.ConsoleTraceListener"/>
</listeners>
</source>
</sources>
<switches>
<add name="app" value="Information"/>
</switches>
<trace>
<listeners>
<add name="Console" type="System.Diagnostics.ConsoleTraceListener"/>
</listeners>
</trace>
</system.diagnostics>
</configuration>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.