Features of Orchard you've never used: Reports

Tags: Orchard, never-used features, Reports

Did you know that there is a module (and a Core module!) in Orchard called Reports? Probably you did because since it's always enabled, you always see its menu item on the admin site. But have you used it at all? Ah, so you haven't either! Let's change this by shortly looking at how it works.

Reports are basically user-accessible logs: you, as a developer, can make your module create reports if it does something notable. For example you could create a report if the module has run something in a background task.

There are two notions to understand regarding reports:

  • Report
  • Report entry

It's not very complicated: reports can be created and they represent a logical collection of report entries; thus report entries can only be added to existing reports. Reports, apart from containing report entries, can have some metadata (like a title), just as report entries (that include a message and timestamp).

There are a couple of interfaces regarding reports but as a module developer you should most possibly only use one, IReportsCoordinator. There are several examples on how to use this in Orchard but let's see it quickly in action:

// _reportsCoordinator is an injected IReportsCoordinator instance and T() is the Localizer as usual.
// Note the usage of T-strings, although ReportsCoordinator accepts normal strings. You can use normal strings too but since these
// messages will be displayed to the user it's probably a good idea to try to localize them. However it would be better if they would
// be localized when being displayed...
_reportsCoordinator.Register("MyModule.Upgrade", T("Upgrade of MyModule").Text, T("Upgrade steps needed to make MyModule use of Orchard 1.8 infoset storage.").Text);
// ...
_reportsCoordinator.Information("MyModule.Upgrade", T("Executing upgrade step 1: initializing the Ultimate Problem Solver.").Text);
// ...
_reportsCoordinator.Warning("MyModule.Upgrade", T("The Ultimate Problem Solver was not found. Resorting to Very Specic Problem Solver.").Text);

You get the idea. BTW as of just now the interface of this service is fully documented, too :-) (check the latest source).

Happy reporting!

No Comments

Add a Comment