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:
DenyAllFilter | This filter drops all LoggingEvent. |
FilterSkeleton | Subclass this type to implement customized logging event filtering |
LevelMatchFilter | This is a very simple filter based on Level matching. |
LevelRangeFilter | This is a simple filter based on Level matching. |
LoggerMatchFilter | Simple filter to match a string in the event’s logger name. |
MdcFilter | Simple filter to match a keyed string in the MDC |
NdcFilter | Simple filter to match a string in the NDC |
PropertyFilter | Simple filter to match a string an event property |
StringMatchFilter | Simple 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>
<filter type="log4net.Filter.DenyAllFilter" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%4t %d{ABSOLUTE} %-5p %m%n" />
</layout>
<encoding value="utf-8" />
</appender>
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:
<root>
<priority value="INFO" />
<appender-ref ref="LogFileAppender" />
<appender-ref ref="UnicornFileAppender" />
</root>
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.