How to do it...

  1. Open your AL project in Visual Studio Code.

The first thing we need to do is configure our project to allow custom telemetry events to be used in our AL code. In Explorer, select app.json. In the Editor window, add the following property:

"target": "Internal"
By adding the previous property to your project, your extension will no longer be supported on the Business Central SaaS platform. In other words, you can only use custom telemetry events in your AL code for on-premises (or possibly private cloud) installations, so be aware of this limitation when designing solutions in case the on-premises customer has plans to move to the cloud.
  1. In Explorer, create a new file named Raise Telemetry Events.al, and in Editor, create a new codeunit object:
codeunit 50130 "Raise Telemetry Events"
{

}
  1. Add a function that will raise the telemetry events:
procedure RaiseEvent(Level: Verbosity)
var
CriticalEventMsg: Label 'A critical event';
ErrorEventMsg: Label 'A error event';
WarningEventMsg: Label 'A warning event';
NormalEventMsg: Label 'A normal event';
CategoryTxt: Label 'Page Action';
EventRaiseMsg: Label 'Event raised';
begin
case Level of
level::Critical:
SendTraceTag('TelEx-000', CategoryTxt, Level,
CriticalEventMsg, DataClassification::CustomerContent);
level::Error:
SendTraceTag('TelEx-001', CategoryTxt, Level,
ErrorEventMsg, DataClassification::CustomerContent);
level::Warning:
SendTraceTag('TelEx-002', CategoryTxt, Level,
WarningEventMsg, DataClassification::CustomerContent);
end;

Message(EventRaiseMsg);
end;
  1. Now, let's try it out! For the purposes of this recipe, I'll assume that you have access to the Event Viewer on the machine where your Business Central Server is located.

Press F5 to build and publish your application:

  1. Using the  icon, search for Telemetry Example and click on it to open it.
  2. Use the various buttons under Actions to log some telemetry events.
  3. Open the Event Viewer on the Business Central Server machine.
  4. Click on Windows Logs | Application.

Depending on the events you logged, you should see some entries in the log, such as this example:

I've highlighted the elements in the previous screenshot that were set using the SendTraceTag call in our AL code.

If you are using a container-based sandbox, you have to get the event log in a slightly different way. You can do this by using the Get-NavContainerEventLog command-let that is part of NavContainerHelper.

Example:
Get-NavContainerEventLog -containerName mycontainer
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.15.221.133