Logging Custom Messages/Exception from IoT Edge Custom module in C# to IoT Hub

Satyam Chauhan 512 Reputation points
2022-09-20T09:13:17.867+00:00

Hi,

We have created a C# custom module, which sends messages to IoT Hub with SendEventAsync Method. There may be a case when some problem occurs in the module, I wanted to send some logs to IoT hub so that I can monitor if the module is working fine or some problem has occurred. I want to send both success and failure response.

Please let me know any solution how can I log custom logs in C# modules and see the same from Cloud/Portal.
Thanks,
Satyam

Azure IoT Edge
Azure IoT Edge
An Azure service that is used to deploy cloud workloads to run on internet of things (IoT) edge devices via standard containers.
543 questions
Azure IoT Hub
Azure IoT Hub
An Azure service that enables bidirectional communication between internet of things (IoT) devices and applications.
1,128 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Sander van de Velde 29,281 Reputation points MVP
    2022-09-20T17:51:12.983+00:00

    Hello @Satyam Chauhan ,

    the simplest way is sending separate messages based on exceptions or error flow inside the modules.

    These messages are preferably sent over a separate output. These 'error' outputs are routed on the edge to $upstream.

    Notice, these messages have probably a different body format compared to the regular telemetry. I suggest adding an application property telling the body contains an exception/success/failure.

    When these 'error' messages arrive in the IoT Hub, you can route them to a custom/separate endpoint, eg. an Event Hub.

    From there you can respond in real-time if these 'error' messages arrive.

    It's a good idea to store these message in a blob storage or Azure Data Explorer for historical purposes.

    2 people found this answer helpful.