你好,有没有一个类可以进行漂亮的转换?
最佳答案
没有内置任何东西,但它会相当容易。
只需捕获 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/