Sitecore 9 PaaS - Disable Application Insights

The first part of this post will be about why Azure Application Insights is an amazing and indispensable component of your Sitecore architecture. The second part of the post will tell you how to disable it. What?!? Read on...

PART 1 - WHY APPLICATION INSIGHTS IS SO AWESOME

Application Insights is an extensible Application Performance Management (APM) service for web developers in Microsoft Azure. When you use the Sitecore Marketplace ARM templates to deploy Sitecore 9 to Azure PaaS, your app services are wired up by default to use the Application Insights instrumentation for all logging. (You can also set up your on-premises Sitecore servers to use AI).

Application Insights is an impressive tool, and Sitecore developers have been asking for a solution like this for a long time. It allows you to have a 360-degree view of your entire Sitecore platform, which can include dozens of App services. It lets you monitor health and performance and easily and quickly find and drill down into problems so you can fix them. You can query all your Sitecore logs (including standard Sitecore logs, and your own custom logs), all in one place. I personally LOVE Application Insights and see it as a major step forward in monitoring and troubleshooting Sitecore.

Here are some screen shots showing App Service metrics you can see in Azure Application Insights:

PART 2 - HOW TO USE LOG4NET INSTEAD OF APPLICATION INSIGHTS

So now I'll show you how to disable Application insights in Sitecore 9 PaaS so you can go back to the old way of generating Log4Net log files on your servers.

Why on Earth would you want to do that? Well, the main, and possibly only, reason would be Azure hosting cost savings.

I wouldn't recommend this for a production environment, but if you're running Sitecore in a sandbox or development environment, or you're just doing a simple demo site or testing some functionality, then why would you want to pay for the Application Insights app? It can be rather expensive to operate because you're billed depending on the amount of data AI receives and processes - and even for an idle demo site that can add up to substantial spend. Better to disable that functionality and just use the good-old Log4Net file logging. Bill Gates has plenty of money - he doesn't need your spare change at this point.

Here's the cost estimate from a non-production demo site (your costs will vary, of course):

You can reduce your Application Insights cost by throttling back your telemetry sampling or capping the amount of data AI can receive, but either of those solutions seem pointless because you will miss out on important log data.

So let's save that $90/month and put it back in your pocket by disabling AI completely from your App Services.

1. Locate the "Sitecore.Cloud.ApplicationInsights.config" in your <website root>\App-Config\Include\zzz folder, and disable it by adding ".disabled" to the end of the filename.

2. In your "ConnectionString.config" file found in <website root>\App_Config, remove the connection string for the AI instrumentation.

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

3. In your <website root>\web.config file, comment out the following entries:

<add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web" preCondition="managedHandler" />
<httpModules>
    <add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web" />
</httpModules>
<dependentAssembly>
    <assemblyIdentity name="Microsoft.ApplicationInsights" publicKeyToken="31bf3856ad364e35" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-2.3.0.0" newVersion="2.3.0.0" />
</dependentAssembly>
<system.diagnostics>
    <trace autoflush="true" indentsize="0">
        <listeners>
            <add name="myAppInsightsListener" type="Microsoft.ApplicationInsights.TraceListener.ApplicationInsightsTraceListener, Microsoft.ApplicationInsights.TraceListener" />
        </listeners>
    </trace>
</system.diagnostics>

Perform these steps on the following server roles:

  • CM
  • CD
  • PRC
  • REP

Once you do that, you should start seeing your Log4Net logs in your website's App_Data/Logs folder, just like the old days.

Finally, you can delete the AI service in Azure to stop the billing.

I hope some folks out there in Sitecore land find this information useful. As always I WANT TO HEAR FROM YOU if you suggestions on how to make my blog better, or if you have better ways of doing things.

Cheers,
~David

Comments (1) -

  • Thanks for this, it was super helpful for debugging. One thing that I did was to use the SCM Powershell console to tail the log file. You can access it by going to https://<yourappservice>.scm.azurewebsites.net, going to Debug Console > Powershell, navigating to the log directory, and doing "Get-Content <logfile> -Wait -Tail 5"

Add comment

Loading