Scroll

Server Event: Manually log execution metadata to file

This server event can be used to manually record some report execution metadata. This may be useful in cases where the built-in logging and monitoring are unavailable, and an ad hoc solution is necessary.

Note: The output is formatted as JSON in this example.

Global Event: OnReportExecuteEnd

Namespaces:

  • System.Text,
  • WebReports.Api.Reports

Code

string fileName = @"C:\Exago\ReportMetadata.txt"; // output file

// collect report metadata
string ReportId = string.Format("\"ReportId\": \"{0}\"", sessionInfo.Report.Id);
string ReportPath = string.Format("\"ReportPath\": \"{0}\"", sessionInfo.Report.Name);
string ReportType = string.Format("\"ReportType\": \"{0}\"", sessionInfo.Report.ReportType);

// collect system info
string TimeStamp = string.Format("\"ExecutionTime\": \"{0}\"", DateTime.Now.ToString());

// get userId parameter
string UserId = string.Format("\"UserId\": \"{0}\"", sessionInfo.UserId);

// build output string as json
// individual elements are formatted above, except report entities, which we build here
StringBuilder sb = new StringBuilder("{\n");
sb.Append(ReportId);
sb.Append(",\n");
sb.Append(ReportPath);
sb.Append(",\n");
sb.Append(ReportType);
sb.Append(",\n");

// list the entities on the report
sb.Append("\"Entities\": \n{\n");
foreach(Entity entity in sessionInfo.Report.Entities)
{
  sb.Append("\t\"Id\": ");
  sb.Append("\"");
  sb.Append(entity.Id);
  sb.Append("\"\n");
}
sb.Append("}\n");          
sb.Append(UserId);
sb.Append(",\n");
sb.Append(TimeStamp);
sb.Append("\n");
sb.Append("}\n");

System.IO.File.WriteAllText(fileName, sb.ToString());

return null;

Output

{ "ReportId": "bde41b48-c0da-4e5d-bafd-95c603825c14", "ReportPath": "Other\OrderInfo", "ReportType": "Standard", "Entities": { "Id": "OrderDetails_0" "Id": "Orders_0" } "UserId": "Scott", "ExecutionTime": "2016-02-19 13:26:25" }

Hidden Article Information

Article Author
Scott Epter
created 2016-02-19 18:37:51 UTC
updated 2017-06-19 17:54:07 UTC

Labels
SAE, metadata, server event, events, example, execution,
Have more questions? Submit a request