Logging your App Activity

It is good practice to have some audit log of what uses do in the application. Some versions ago Microsoft introduced the Change Log to log data changes. How about logging an action execution?

One of the built in solutions in Business Central can be used to solve this. We now have the Activity Log (Table 710).

To use the Activity Log we need to have a record to attach the activity log to. All our Apps have a Setup table that usually only have one record. I like to attach my Activity Log to that record.

To show the Activity Log from that record you can add this action to that record’s page.

The logging part can be something like this.

We also have the possibility to log details. Both a text value and also from an in-stream.

In Business Central we have information about the execution context. I pass that execution context into the LogActivity. This gives me information on the session that is executing the code.

Using this logic we can log all execution during install, upgrade and normal user cases. If we need information on the variables we can log them into the detailed information using either JSON or XML.

Automatic EMail from Change Log

I have been asked for a solution that can send an email when a customer is changed.  I have a few objects created and a codeunit that is executed by the Job Queue or manually from a page or a form.  First the Change Log needed to be activated.

Then after installing the attached object and adding page or from 77170 to the menu suite I can setup an email address for each table and each trigger.

Attached is the needed code, Change Log EMailer