IOT Diagnostic logs

How To Setup Diagnostic logs with an IoT Hub

In this article, you’ll see the steps to enable the diagnostic logs with an IoT Hub. if a problem occurs in your IoT Hub solution which running in the production you want to enable the diagnostic logs. It will help you to diagnose the problem and fix it immediately.

Please read the previous parts of the article before continuing with this one

1. How To Create Azure IoT Hub Using PowerShell

2. How to Register IoT Device in Azure IoT Hub Using PowerShell

3. How To Send Telemetry From An IoT Device To The Azure IoT Hub Using C#

Enable the diagnostic logs

When creating a new IoT Hub the diagnostic logs are disabled by default. Lets see how to enable it.

  • Open your Azure portal and login to your Azure account.
  •  Select your IoT Hub from the resource groups.
  •  Click Diagnostic settings in the Monitoring section . You can see the diagnostic status is disabled by default.

Diagnostic settings

  •  Now double click the resource, you can see the Turn on diagnostics like below image.

Diagnostic storage settings

 Enter the name for your diagnostic setting. Here I name as diags-hub.

 Check Archive to a storage account.

 Click configure to select the storage account screen.

 Choose your storage account and click ok to return to the diagnostic settings pane.

Select Diagnostic storage account

 Under LOG , Check Connections and Device Telemetry and set the Retention (days) 7 Days for each. You Diagnostic setting should looks like below image

 Click Save to save the settings. Close the Diagnostic settings pane.

 You can see new setting that we created in the below image.

IoT Hub connections and device telemetry logs are sent to the specified destination as soon as  new event data is generated.

To See the diagnostic logs

 Go to your resource group and select your storage account Hubflyiotstoragedev

 Select the Blobs from the Blob service, you can see the insight-logs-connections 

 Select the insight-logs-connections container . Drill down until you get the current date and choose the recent file.

 Click Download to download and open it. You can see the logs of device connections and device telemetry to IoT Hub. see the below image sample

Thats it, I hope you have learned how to setup diagnostic logs with an IoT hub. Feel free to fill up the comment box below if you need any further assistance.

Sharing is Caring!

Leave a Reply

Your email address will not be published. Required fields are marked *