PandaWood / ExceptionReporter.NET

ExceptionReporter is a .NET component that gathers detailed information on an Exception and the application/system running it. It allows the user to copy, save or send a custom-formatted report to the developer
MIT License
51 stars 32 forks source link

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

Closed PandaWood closed 6 years ago

PandaWood commented 6 years ago

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)

PandaWood commented 6 years ago

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}}

========================================
PandaWood commented 6 years ago

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