I was looking through our Fresh Dev Environment and noticed the following message in Application Insights:

Nobody Samples my Data!

Looking at the latest items showing up, it was pretty clear that the ever-so-loved chatty nature of Sitecore was causing Application Insights to throw a bit of a fit. Rightly so. We all know how much fun it is to comb the log files, right? After doing some research, I came across this lovely blog post by Brian Pederson in how to trim out some of the junk. It was a real gem, and relies on the filters in log4net. This was for sure worth trying out!

Unfortunately, things weren’t shaping up. It turns out that things changed a bit and the standard, good ol’ LogFileAppender is where you want to target your changes. I’ve provided the config I used to do the deed. Special note to the “key” attribute. Without that, your patch elements will transform each other, since there’s no unique identifier to distinguish them for each other.

<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
  <sitecore>
    <log4net>
      <root>
        <appender-ref ref="LogFileAppender" patch:after="appender-ref[@ref='LogFileAppender']" />
      </root>
      <appender name="LogFileAppender" type="Sitecore.Cloud.ApplicationInsights.Logging.Log4NetAppender, Sitecore.Cloud.ApplicationInsights" patch:after="appender[@name='LogFileAppender']">
        <filter type="log4net.Filter.StringMatchFilter" key="JS">
          <stringToMatch value="Job started: Sitecore." />
          <acceptOnMatch value="false" />
        </filter>
        <filter type="log4net.Filter.StringMatchFilter" key="JE">
          <stringToMatch value="Job ended: Sitecore." />
          <acceptOnMatch value="false" />
        </filter>
        <filter type="log4net.Filter.StringMatchFilter"  key="PA">
          <stringToMatch value="[Path Analyzer](.) Map EnsureAllDeployed started." />
          <acceptOnMatch value="false" />
        </filter>   
        <filter type="log4net.Filter.StringMatchFilter"  key="ND">
          <stringToMatch value="Not due:" />
          <acceptOnMatch value="false" />
        </filter> 
        <filter type="log4net.Filter.StringMatchFilter"  key="CC">
          <stringToMatch value="Cache created:" />
          <acceptOnMatch value="false" />
        </filter> 
        <filter type="log4net.Filter.StringMatchFilter"  key="JSIU">
          <stringToMatch value="Job started: Index_Update_IndexName=" />
          <acceptOnMatch value="false" />
        </filter>
        <filter type="log4net.Filter.StringMatchFilter"  key="JEIU">
          <stringToMatch value="Job ended: Index_Update_IndexName=" />
          <acceptOnMatch value="false" />
        </filter>  
        <filter type="log4net.Filter.StringMatchFilter"  key="HTTP">
          <stringToMatch value="HttpModule is being initialized" />
          <acceptOnMatch value="false" />
        </filter>
        <filter type="log4net.Filter.StringMatchFilter"  key="FD">
          <stringToMatch value="File is being deleted by cleanup task" />
          <acceptOnMatch value="false" />
        </filter>
        <filter type="log4net.Filter.StringMatchFilter"  key="IAR">
          <stringToMatch value="IAssemblyResolver contains" />
          <acceptOnMatch value="false" />
        </filter>
        <filter type="log4net.Filter.StringMatchFilter"  key="HEA">
          <stringToMatch value="Health" />
          <acceptOnMatch value="false" />
        </filter>
      </appender>
    </log4net>
  </sitecore>
</configuration>

You can see the noticeable change in my logging once this had been running for a bit:

You’re going to want to tweak this however you see fit, but this hopefully is a good start for you. Again, super thanks to Brian for the start for this!

Facebooktwitterredditlinkedinmail