Azure Application Insights. Writing log files and telemetry from on-premise Sitecore instances

One can use Azure Application Insights also in on-premise scenarios.
There are at least following things to consider before doing that:

  1. Application Insights is not free of charge
  2. On-premise servers should have access to Azure Application Insights endpoints
  3. Think about writing to the Application Insights in the nearest region to your on-premise servers (however a higher latency here should not be that)
  4. Probably something else that I didn't consider...
Sitecore supports Azure Application Insights out-of-the-box for PaaS deployments. That means if you use either ARM templates to deploy or deploy from Azure Marketplace you'll get logging into Application Insights automatically.
However, even for on-premise applications (or applications hosted in another cloud provider) you can use Azure Application Insights.
Let's see what steps you need to do in order to make vanilla Sitecore to write into application insights trace log (simply speaking - Sitecore log file) as well as Sitecore Performance counters.

Initial steps

  1. Install vanilla Sitecore 9.1 Update-1 XP Single on local machine, on-premise server or anywhere into VM
  2. Make sure the server machine has access to Application Insights endpoint (see above in this post)
  3. Create Application Insights Service into your Azure Subscription (yes, for that you need to have an Azure Subscription)
  4. Download Sitecore WDP package for Azure AppService from
  5. Unzip that WDP package and be ready to copy some configuration files and configuration snippets from it to your installed vanilla on-premise Sitecore

Copy DLLs

Copy following DLL files from WDP package to bin folder of the on-prem Sitecore instance:
  • All DLLs with names starting from "Microsoft.AI"
  • All DLLs with names starting from "Microsoft.ApplicationInsights"
  • "Sitecore.Cloud.ApplicationInsights.dll"

Copy config files

Copy following config files from WDP package to "App_Config/Include" folder:
  • Sitecore.Cloud.ApplicationInsights.config
  • Sitecore.Cloud.ApplicationInsights.Counters.config
  • Sitecore.EmailExperience.Logging.Azure.config
Copy file "websiteroot\ApplicationInsights.config" from WDP package to the website root of the on-premise Sitecore.

Config files changes

Add new connection string to the ConnectionStrings.config file:

<add name="appinsights.instrumentationkey" connectionString=""/>

The value of that connection string should be the instrumentation key of Azure Application Insights service that you have created:

You may also want to configure following settings in Sitecore.Cloud.Applicationinsights.config file

Especially setting might have a sense if you have scaled Sitecore setup and want to clearly see the telemetry data by each role.
So, if you set:

<setting name="ApplicationInsights.Role" value="SingleBoxPc" />

You will see something like this in Application Insights:

You should also do some changes to web.config. You can copy changes below from the web.config in WDP package:
Add following 2 keys:

Add a handler to system.webServer section:

Finally, add a couple of assembly bindings and trace listener to system.diagnostics:

Restart IIS Application Pool

Open website, navigate through Sitecore, wait few minutes to get let Application Insights service to receive telemetry and then enjoy exploring that data:

Note: you may notice that "performanceCounters" table may be empty. I think that is related to the fact that when connecting on-premise application, you need to explicitly specify names of the performance counters that should be written to Application Insights. However, I have not checked this.
Sitecore specific performance counters are stored in "customMetrics" table.