It very easy to setup and use Azure Insights in Business Central.

You can read how to set it up here

But how to actually analyze the logs in Azure?

First I’ll set up some custom events that I want to send to Azure.

Little wrapper around the Session.LogMessage so its easier to use:

    local procedure LogMessage(EventId: Text[50]; Message: Text[200]; Dimension: Text[50])
    var
        TelemetryDimensions: Dictionary of [Text, Text];
    begin
        TelemetryDimensions.Add('Method', Dimension);
        Session.LogMessage(
            EventId,
            Message,
            Verbosity::Warning,
            DataClassification::SystemMetadata,
            TelemetryScope::ExtensionPublisher,
            TelemetryDimensions
        );
    end;

And now I can call it from my code:

    local procedure SlowAndPainful()
    var
        Customer: Record Customer;
        Error001: Label 'Too slow, too painful';
    begin
        Customer.Init();
        Customer."No." := '8931lzx';
        Sleep(5000);
        Customer.Insert();
        LogMessage('debug-solution', Error001, 'SlowAndPainful');
        Error(Error001);
    end;

Here I have method that gives error and instead of only showing it to the user I want to log this out as well so I can find out later that the issue indeed has happened and have some context about it.

First to find logs Choose Logs in Insights and then Traces:

Find logs

From Traces you can probably find already your custom logs and the related information:

Find logs

And with this information you can start building some interesting queries. For example check out the daily bins for the errors and other custom messages that have appeared:

Find logs