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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With