PandaWood/ExceptionReporter.NET

Use templating for creating reports - for design and flexibilty (eg HTML or Text reports)

PandaWood opened this issue · 2 comments

The massive string manipulation/gathering in ExceptionReporter to create a textual report is a throw-back to it's ancient origins...

It seems to me that it should use a template-based approach - as is often used to generate HTML in javascript/frameworks and libraries like Mustache

I think using templates would produce clearer/simpler code for generating the report and remove all the StringBuilder operations.
It would also add the flexibility of creating new templates for different report formats like allowing for Text or HTML
A user could even create their own template and customize the report...

We could just roll our own simple text substitution for much of it, but some of the more complex rendering of lists might benefit from a templating library eg mustache-sharp (except this one doesn't support .NET 4)

I'm using Handlebars.NET for this - partly because it had the lowest .NET Framework support I could find (.NET 4 in v1.9))

The text template looks something like below (I'll fix it a bit more)

The final choice will be to allow the user to create their own Handlebar template.

Only problem will be that we'll need to move to .NET 4.5.2 dependency to complete this.
(this is not a problem anymore as v1.9 supports .NET 4)

A lot of awkward code using StringBuilder appending and manipulation will be deleted when this is completed - and it will be better unit tested.

========================================

[General Info]

  Application: {{App.Name}}
  Version:     {{App.Version}}
  Region:      {{App.Region}}
{{#if App.User}}
  User:        {{App.User}}
{{/if}}
  Date: {{Error.Date}}
  Time: {{Error.Time}}
{{#if Error.Explanation}}
  User Explanation: {{Error.Explanation}}
{{/if}}

Error Message: {{Error.Message}}
 
[Stack Traces]
 
  {{Error.FullStackTrace}} 
 
[Assembly References]
 
{{#App.AssemblyRefs}}
  {{Name}}, Version={{Version}}
{{/App.AssemblyRefs}}

[System Info]
 
  {{SystemInfo}}
 
========================================

Have basic templates for text/markdown/html - all tested