I recently had a requirement to log exceptions from Logic Apps.

Because the source for logging exceptions could change, I decided that the easiest way to do this was to create a Logic App just for handling exceptions.  Logic Apps as so easy to modify, where API Apps require code changes and re-publishing.

In order to standardize, I started off by creating a schema, as shown in the following code sample.

{
    "schema": 
    {
        "properties": 
        {
            "message": 
            {
                "description": "The result code for this particular action. For http-style actions, it will typically be the http response, such as OK or InternalServerError.",
                "format": "",
                "type": "string"
            },
                        "CRMId": 
            {
                "description": "CRM Id from Request",
                "format": "",
                "type": "string"
            },
            "Source": 
            {
                "description": "The name of the particular action as defined in the definition.",
                "format": "",
                "type": "string"
            },
            "trackingid": 
            {
                "description": "GUID. The unique ID passed to only this particular trigger in the x-ms-tracking-id header. This can be used for correlation with error logs.",
                "format": "",
                "type": "string"
            },
            "Sendmessage._Properties": 
            {
                "description": "Key-value pair of all brokered message properties and user properties",
                "format": "",
                "type": "object",
                "endTime": 
                {
                    "description": "Time that the action reached a terminal state (Succeeded, Failed or Skipped). There will be no time present if the flow is currently executing.",
                    "format": "",
                    "type": "date-time"
                },
                "startTime": 
                {
                    "description": "Time that the action first started executing.",
                    "format": "",
                    "type": "date-time"
                },
                "id": 
                {
                    "description": "The id field should be the URL (excluding the hostname/scheme and api version) for the flow. It should not be URL encoded.",
                    "format": "",
                    "type": "string"
                },
                "inputs": 
                {
                    "description": "An object representing the data that was passed to this particular action..",
                    "format": "",
                    "type": "object"
                },
                "outputs": 
                {
                    "description": "An object representing the results of the action.",
                    "format": "",
                    "type": "object"
                },
                "required": 
                [
                    "message",
                    "CRMId",
                    "Source",
                    "trackingid",
                    "Sendmessage._Properties"
                ],
                "type": "object"
            }
        }
    }
}

Starting off in the Designer View (I haven’t figured out how to start off in Code View 😉 )  as  shown in the following screenshot.

I used a Manual Trigger,  because the Logic App was to be consumed by other Logic Apps.

 

The Code View is as follows:

{
    "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2015-08-01-preview/workflowdefinition.json#",
    "actions": {
        "Send_message.": {
            "conditions": [],
            "inputs": {
                "body": {
                    "ContentData": "SOURCE:   @{triggerBody()['Source']}/nDESCRIPTION:   @{triggerBody()['Message']}/nCRM Id:   @{triggerBody()['CrmId']}/nTRACKING ID:   @{triggerBody()['trackingid']}/n/n",
                    "ContentTransferEncoding": "None",
                    "Properties": "@triggerBody()['Sendmessage']['_Properties']"
                },
                "host": {
                    "api": {
                        "runtimeUrl": "https://logic-apis-eastus.azure-apim.net/apim/servicebus"
                    },
                    "connection": {
                        "name": "@parameters('$connections')['servicebus']['connectionId']"
                    }
                },
                "method": "post",
                "path": "/@{encodeURIComponent(string('exceptions'))}/messages"
            },
            "type": "ApiConnection"
        }
    },
    "contentVersion": "1.0.0.0",
    "outputs": {},
    "parameters": {
        "$connections": {
            "defaultValue": {},
            "type": "Object"
        }
    },
    "triggers": {
        "manual": {
            "inputs": {
                "schema": {
                    "properties": {
                        "CrmId": {
                            "description": "CRM Id",
                            "format": "",
                            "type": "string"
                        },
                        "Message": {
                            "description": "Description of the exception",
                            "format": "",
                            "type": "string"
                        },
                        "Sendmessage._Properties": {
                            "description": "Key-value pair of all brokered message properties and user properties",
                            "format": "",
                            "type": "object"
                        },
                        "Source": {
                            "description": "Source of the exception",
                            "format": "",
                            "type": "string"
                        },
                        "trackingid": {
                            "description": "GUID. The unique ID passed to only this particular trigger in the x-ms-tracking-id header. This can be used for correlation with error logs.",
                            "format": "",
                            "type": "string"
                        }
                    },
                    "required": [
                        "CrmId",
                        "Message",
                        "Sendmessage._Properties",
                        "Source",
                        "trackingid"
                    ],
                    "type": "object"
                }
            },
            "type": "Manual"
        }
    }
}

 

Additional Action Metadata

There are two Object  properties, Inputs and outputs,  both contain the following:

Field Description
uri String.  The location of the link to follow to get the inputs.
contentVersion String.  The version of the content.
contentSize The number of bytes at the link.
contentHash An object representing the hash of the content.
metadata An object that can contain additional fields.

∗ contentHash contains the following:

Field Description
algorithm String. The algorithm used to hash the content.
value String. The hash with the respective algorithm.

 

Note:  An object isJSON Data  Type.  Wikipedia defines Object as  an unordered collection of name/value pairs where the names (also called keys) are strings.