Search code examples
windows-10-universalwindows-10-mobileazure-application-insights

How to add application insights config file to windows 10 universal apps


I have updated visual studio 2015 update 3, for update 1 config file added using instructions in the Url , but it's not working how can i send insights to azure in windows 10 universal app,


Solution

  • Which url are you using?

    for VS2015 update 3, you'll have to:

    1) manually add the microsoft.applicationinsights.windowsapps package using nuget package manager

    2) add startup code in your App.xaml.cs, in the App constructor:

    public void App()
    {
        // add this code to initialize AI.  do not await here, you'll slow down
        // app startup, use continuewith to get/set any AI thing you need after
        // it initializes
        WindowsAppsInitializer.InitializeAsync().ContinueWith( t =>
          {
               // any other code you need to do with app insights here
          }, continuationOptions: TaskContinuationOptions.OnlyRanToCompletion );
    
         this.InitializeComponent();
         // ... any other startup code here
     }
    

    3) if that does not add an applicationinsights.config file to your project, manually create a text file that is, in its entirety:

    <?xml version="1.0" encoding="utf-8"?>
    <ApplicationInsights>
        <InstrumentationKey>[your key here]</InstrumentationKey>
    </ApplicationInsights>
    

    (some versions of the instructions use an old sample of the config file that has some comments in it, and the comments include an <InstrumentationKey> tag, and for perf reasons, the windows apps sdk startup uses a regular expression to find the key instead of loading a full xml parser, so if there are comments with an instrumentation key, it will use that as your ikey instead of the real xml!)

    4) add that file to your project in VS, and set its properties to:

    Build Action: Content
    Copy to Output Directory:  Copy if Newer
    

    (which would look like this in your .csproj)

    <Content Include="ApplicationInsights.config">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </Content>
    

    you don't need an applicationinsights.config file if you are manually setting the instrumentation key in code, in the call to InitializeAsync.