c# - 如何最好地将堆栈跟踪转换为 HTML(使用 .NET - C#)

标签 c# .net html

你好,有没有一个类可以进行漂亮的转换?

最佳答案

没有内置任何东西,但它会相当容易。

只需捕获 StackTrace :

// Create trace from exception
var trace = new System.Diagnostics.StackTrace(exception);

// or for current code location
var trace = new System.Diagnostics.StackTrace(true);

一旦你有了这个,只需迭代堆栈帧,并根据需要格式化它们。

有很多方法可以将其格式化为 HTML - 这实际上取决于您希望它的外观。基本概念是:

int frameCount = trace.Framecount;
for (int i=0;i<frameCount;++i)
{
     var frame = trace.GetFrame(i);
     // Write properties to formatted HTML, including frame.GetMethod()/frame.GetFileName(), etc.
     // The specific format is really up to you.
}

关于c# - 如何最好地将堆栈跟踪转换为 HTML(使用 .NET - C#),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1382230/

相关文章:

c# - 继承 : possible to change base reference to something else?

c# - 将导航属性映射到存储过程

html - 带有文本的 Div 覆盖图像

c# - Entity Framework - CSDL、SSDL 和 MSL 文件

c# - C#Youtube api V3-值不能为空错误异常

.NET 3.5图表控件异常: Error executing child request for ChartImg. axd

javascript - 如何在 react 中消失 "button"元素?

javascript - Firefox 中的 jQuery 问题

c# - 将两个整数映射到一个(有上限)

c# - OxyPlot 热图问题 Windows 8.1 通用应用程序 VS 2015 : Plot won't draw