Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Application Insights with Windows 10 IoT Core

There is a great guide for using Application Inights in Windows Apps: Application Insights for Windows Phone and Store apps.

Any best practices for using Application Insight with Windows 10 IoT Core? I see an interesting usage for using Application Insigts as a easy to use event logging mechanism to monitor headless App running state.

like image 744
1iveowl Avatar asked Mar 05 '26 16:03

1iveowl


1 Answers

Here are my finding.

Don't use: WindowsAppInitializer.InitializeAsync("1234567-1111-1234-1234-1234567890ab"); to initialize Application Insights as this will crash the IoT App.

I used somwthing like this instead:

public sealed class StartupTask : IBackgroundTask
{
    private BackgroundTaskDeferral _defferal;

    internal static TelemetryClient TelemetryClient = new TelemetryClient();


    public StartupTask()
    {
        TelemetryClient.InstrumentationKey = "1234567-1111-1234-1234-1234567890ab";

    }

    public async void Run(IBackgroundTaskInstance taskInstance)
    {
        var cancellationTokenSource = new System.Threading.CancellationTokenSource();
        taskInstance.Canceled += TaskInstance_Canceled;

        _defferal = taskInstance.GetDeferral();
        ... [insert your code]...
    }
}

To use the Application insights I just use StartupTask.TelemetryClient.TrackEvent("Some event") or some of the other App Insight methods wherever I need too.

like image 143
1iveowl Avatar answered Mar 07 '26 06:03

1iveowl



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!