Azure Monitor Logs (formerly Log Analytics) is a fundamental feature of Azure Monitor Service. It is a set of tools allowing :
- Azure resources or any external resource to send logs
- Data analysis through the Log analytics portal
By design, Azure resources can send automatic logs to a linked Log Analytics workspace. Note that each resource sends appropriate data (so different kinds of data) to the workspace.
Unlike the Metrics, Logs can store different data types (dates, strings…) and are organised as records. It’s worth to say the Logs base can also be filled with custom logs (for instance by using the Log Analytics APIs as shown on the previous picture), and it’s exactly the purpose of this post: How to send custom log analytics data through Azure Logic Apps.
Create your Log Analytics Workspace
First of all, you need to have a dedicated Log Analytics workspace. If you don’t have one, you can create a new resource of Log Analytics workspace type using the Azure portal.
Just fill the form with:
- The workspace name
- The related Azure subscription
- A resource group (create a new one or use an existing one)
- The data center to host your workspace
- A pricing tier (free tier in this sample)
That’s it, you can now send logs to Azure Monitor Logs.
Link your Logic App to your Log Analytics workspace
In order to send logs, your Logic App needs to be linked with the workspace. You can link it on the Logic App creation step as shown on the following picture.
Generate logs from the logic app
The link between the workspace and the Logic Apps activates automatic logs:
- Start/end of each run
- Start/end for each action
- Run ids, Resource group, resource name…
All of these are technical logs. However, sometimes you need to trace other business data. For instance, you might want to log an « order number » from incoming orders to build business dashboards or improve the monitoring of your logic app runs.
From any Logic App action, you can configure tracked properties which will be sent to the Log database. Just use the « Settings » command behind the ellipsis on the top right corner of the related action.
In the following screenshot, we just track 2 data entries. One of these is the subject of an outgoing Email.
Request the Log database
In order to request the log database, you need to use the Kusto language (https://docs.microsoft.com/fr-fr/azure/kusto/query/). It’s a relatively easy to understand query language and it’s close to SQL syntax.
In the following example, the query gets all the logs related to the subject “log”.
Before processing, keep in mind that:
- The logging step occurs after the action is completed
- You have some limitation when using tracking properties (for instance, you can use the input/output of the related step but not from previous steps)
- If your tracking fails, the action ends with a Failed state, which will probably have consequences for your Logic App workflow
- If you want to use a column as a predicate, it has to exist: it only means that at least one process has to create a log with the column (for instance a Logic App)