Logging To Azure Log Analytics WorkSpace From MS Flow

Introduction

 
In this blog, we will learn how to log messages to Azure Log Analytics workspace using MS Flow.
 
Prerequisite
  • Log Analytics workspace should be created
  • Workspace ID, primary key should be known beforehand 

Steps to be used in flow

 
Firstly, we will create a simple MS flow log the message in Log Analytics. Please follow below steps.
  1. Create a flow with manual trigger.

    Logging To Azure Log Analytics WorkSpace From MS Flow

  2. Click on ‘New Step’ and search for ‘Send data’ and select ‘Send Data’ action.

    Logging To Azure Log Analytics WorkSpace From MS Flow

  3. Once you select the action, it will be available on the flow and will ask for the following details.

    Logging To Azure Log Analytics WorkSpace From MS Flow

  4. Now in the Connection Name, you can put relevant name, which will be used while querying the logs for Log Analytics. I am putting – FlowLALogging

  5. In the workspace Id and Workspace key, put respective values from log analytics.

  6. To know the workspace id, open the log analytics and click on overview.

    Logging To Azure Log Analytics WorkSpace From MS Flow
  7. To get the Workspace Key, go to advanced setting and copy primary or secondary key.

    Logging To Azure Log Analytics WorkSpace From MS Flow

  8. After entering the values once you click on Create, the ‘Send Data’ action will be changed as below,

    Logging To Azure Log Analytics WorkSpace From MS Flow

      • Enter values in all the three fields as follows
      • JSON Request body - Message to be logged in, should be in JSON format.
      • Custom LOG Name – Connection name used in step 5. For me it is FlowLALogging
      • Time-generated-field Represents the date and time of logging.
  9. The JSON request body should be in below format,
    1. [  
    2.    {  
    3.       "Action 1""Testing LA Logging 1",  
    4.       "Action 2""Testing LA Logging 2"  
    5.    }  
    6. ]  
  10. In the custom Log Name – FlowLALogging

    Logging To Azure Log Analytics WorkSpace From MS Flow
  11. Now save the workflow and run it manually.
  12. Your flow should run successfully.
  13. Now wait for 5 minutes so that log data should be available for query.
  14. After 5 minutes go to Log Analytics - Log and run below command.
  15. FlowLALogging_CL| limit 50
    ‘_CL’ is the suffix added for each custom key. It stands for Custom Logging.

    Logging To Azure Log Analytics WorkSpace From MS Flow