How to collect Unicorn logs in a separated file?

In one of my projects, Unicorn is used to Sitecore items synchronization. Time to time during items synchronization we can notice problems during sync process. Unicorn logs are part of Sitecore global log file, but I decide to have Unicorn logs in a separated file.

Sitecore uses log4net framework for logging infrastructure. Log4net has many configuration options and provides filters functionality:

DenyAllFilterThis filter drops all LoggingEvent.
FilterSkeletonSubclass this type to implement customized logging event filtering
LevelMatchFilterThis is a very simple filter based on Level matching.
LevelRangeFilterThis is a simple filter based on Level matching.
LoggerMatchFilterSimple filter to match a string in the event’s logger name.
MdcFilterSimple filter to match a keyed string in the MDC
NdcFilterSimple filter to match a string in the NDC
PropertyFilterSimple filter to match a string an event property
StringMatchFilterSimple filter to match a string in the rendered message

Base on filters I configured Unicorn appender, to collect logs in a separated file. Each Unicorn log entry looks like this:

16060 09:57:36 INFO [Unicorn]: [U] master:/sitecore/content/UK/Settings/Datasources/Section (8fec63cb-9d4a-41ac-9eb4-a6058e104ce8)

Each line contains [Unicorn], base on that information I used a StringMatchFilter:

<appender name="UnicornFileAppender" type="log4net.Appender.RollingFileAppender, Sitecore.Logging">
      <file value="$(dataFolder)/logs/unicorn.{date}.{time}.txt" />
      <appendToFile value="true" />
	  <filter type="log4net.Filter.StringMatchFilter">
        <stringToMatch value="[Unicorn]" />
	  <filter type="log4net.Filter.DenyAllFilter" />
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%4t %d{ABSOLUTE} %-5p %m%n" />
      <encoding value="utf-8" />

I don’t want other log entries in my unicorn.log, only Unicorn one, so I have to add DenyAllFilter after StringMatchFilter to disable all other log entries.

Finaly I have to register a new appender:

      <priority value="INFO" />
      <appender-ref ref="LogFileAppender" />
      <appender-ref ref="UnicornFileAppender" />

After this I have all Unicorn logs in a separated files:

In next post I will describe how to create a patch file to apply this Unicorn logger to Sitecore.

Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: