Insights

Improving Sitecore Log Cleanup In Azure

Meet David Austin

Development Team Lead

📷🕹️👪

David is a decorated Development Team Lead with Sitecore Technology MVP and Coveo MVP awards, as well as Sitecore CDP & Personalize Certified. He's worked in IT for 25 years; everything ranging from Developer to Business Analyst to Group Lead helping manage everything from Intranet and Internet sites to facility management and application support. David is a dedicated family man who loves to spend time with his girls. He's also an avid photographer and loves to explore new places.

Connect with David

Sitecore Log Cleanup In Azure

If your Sitecore instance been deployed to an Azure App Service you may, depending on your patch level and even your level of access to the backend, have noticed a growing concern in the log directory. They're not being cleaned up. That is if it's even enabled to be.

The issue stems from the naming convention of Azure logs compared to logs on a Standalone environment.

The Patch File

With that in mind, it's actually quite easy to setup a patch file that will clean up all the azure log files.

Understanding the pattern allows you to even get more specific such that you could in essence have different rules for each type of log file.


<?xml version="1.0" encoding="utf-8" ?>
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/" xmlns:set="http://www.sitecore.net/xmlconfig/set/" xmlns:role="http://www.sitecore.net/xmlconfig/role/">
  <sitecore>
    <scheduling>
      <agent>
        <files hint="raw:AddCommand">
            <remove folder="$(dataFolder)/logs" pattern="*log.*.txt*" maxAge="30.00:00:00" recursive="true" />
            <remove folder="$(dataFolder)/logs" pattern="*azure.*.txt*" maxAge="30.00:00:00" rolling="true" recursive="true" name="AzureLogCleanup" patch:after="remove[@folder='$(dataFolder)/logs']"/>
        </files>
      </agent>
    </scheduling>
  </sitecore>
</configuration>

You'll notice a slight variation in the two lines where we specify the log pattern to look for.

In the second line, where we specified the *azure.*.txt* pattern, we also specified a name="AzureLogCleanup". Without that it would overwrite the default log pattern. Using the name attribute we can have multiple log cleanup patterns in play.

This now allows for two separate log file cleanups based upon different patterns to exist. As you can now see, you could have different log cleanup patterns based upon any number of log types.

The other thing to note is that we added rolling="true". Without this the maxCount and minCount will engage and by default the maxCount is 20.

Here's to keeping your backend clean of old log files and preventing backups from occurring.

Hey, Developers!

We're on the look out for talented developers to join our team.

Think you have what it takes?