简体   繁体   中英

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM