What is the best way to convert stack trace to HTML (using .NET - C #)

Hi, is there a class that does a pretty converting conversion?

+6
html c #
source share
2 answers

There is nothing built in, but it would be pretty easy.

Just take StackTrace :

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

Once you do this, simply move the frames of the stack and format them as desired.

There would be many ways to format this in HTML - it really depends on how you want it to look. The basic concept:

 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. } 
+7
source share

This is not a new question, however I would prefer to use open source nuget, for example. https://github.com/atifaziz/StackTraceFormatter than reinvent the wheel with HTML from scratch.

0
source share

All Articles