6

We would like to make the main Sitecore log file more clean,and filter away all the unnecessary information that makes finding errors and other relevant information harder. After upgrading to Sitecore 8.2 update 5 from Sitecore 7.2, we get the following message several time per second, resulting in 6+ MB log files per day.

INFO Job started: Index_Update_IndexName=sitecore_master_index

Here is an example that contains a few seconds: https://pastebin.com/raw/qjBvaFjW

So basically I have 2 questions here:

1) Is it possible to NOT log these particular messages at all? I haven't really found any examples of using the to manipulate the standard .log file.

2) Is there a way to make log messages containing specific text go to another log file, like indexupdateDATETIME.txt, instead of the log.txt?

1

3 Answers 3

4

As Mark mentioned Sitecore uses log4net so you can use the filtermethods that log4net provides. You can find the options here: https://logging.apache.org/log4net/log4net-1.2.11/release/sdk/log4net.Filter.html

As you can see, there is a StringMatchFilter that you could use to filter out all messages with a specified text (answering your question 2). Haven't tried that one myself yet - found a blog on it's usage here: https://www.kruegerwebdesign.com/blog/how-to-use-the-log4net-stringmatchfilter

To answer your question 1, you can also raise the loglevel, so it doesn't log the info logs anymore. But that would mean that the other info level logs aren't logged anymore either.

You can also move the debug/info logs to another log file as described here: How can I split logs by log level/priority

1
  • Thanks, I'll look into that StringMatchFilter, if I get it to work I'll post here what I did. The split logs by log level looks interesting as an alternative solution if I can't get it to work though.
    – WulfgarDK
    Commented Dec 12, 2017 at 7:05
3

You cans set log priority in the confi section.The following is a list of log levels (priorities) from lowest to highest severity.

  1. DEBUG
  2. INFO
  3. WARN
  4. ERROR
  5. FATAL

Out of Box log pririty set to "INFO", so log will record all levels except "DEBUG". If you dont want info messages in log then you can set it to "WARN".

for more details about logging, yo check at http://sitecore-community.github.io/docs/documentation/Sitecore%20Fundamentals/Logging/

2

We finally got around to implementing this, so I just want to show how I solved it. I added the following lines to the section in our custom Sitecore config file.

<root>
        <appender-ref ref="LogFileAppender" />
        <appender-ref ref="IndexUpdateAppender" />
      </root>
      <appender name="LogFileAppender">
        <filter type="log4net.Filter.StringMatchFilter">
          <stringToMatch  value="Index_Update_IndexName" />
          <acceptOnMatch value="false" />
        </filter>
      </appender>
      <appender name="IndexUpdateAppender"
        type="log4net.Appender.SitecoreLogFileAppender, Sitecore.Logging">
        <file value="$(dataFolder)/logs/IndexUpdate.log.{date}.txt" />
        <appendToFile value="true" />
        <layout type="log4net.Layout.PatternLayout">
          <conversionPattern value="%4t %d{ABSOLUTE} %-5p %m%n" />
        </layout>
        <filter type="log4net.Filter.StringMatchFilter">
          <stringToMatch  value="Index_Update_IndexName" />
          <acceptOnMatch value="true" />
        </filter>
        <filter type="log4net.Filter.DenyAllFilter" />
      </appender>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.