It's easy to get distracted by all the shiny big features that get deployed in new releases of Sitecore, but every so often a little gem slips past almost without comment. Except in the release notes...
One such change that I came across recently was
hiding in plain sight in the notes for v8.1 (rev. 151003). With surprisingly little fanfare, the configuration for Log4Net has been moved under the
<sitecore/>
element in the site's configuration. And hence you can now apply config patches to adjust the log file settings.
It's not a massive thing in the grand scheme, but it adds another useful feature to the list of stuff you can modify with a patch.
So instead of XDT or manual edits, you can now have much more deployment-friendly changes like:
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
<sitecore>
<log4net>
<appender name="MyCustomAppender" type="log4net.Appender.SitecoreLogFileAppender, Sitecore.Logging">
<file value="$(dataFolder)/logs/testlog.{date}.txt"/>
<appendToFile value="true"/>
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%4t %d{ABSOLUTE} %-5p %m%n"/>
</layout>
<encoding value="utf-8"/>
</appender>
<logger name="MyCustomLogger" additivity="false">
<level value="INFO"/>
<appender-ref ref="MyCustomAppender"/>
</logger>
</log4net>
</sitecore>
</configuration>
It's probably of most use when you're building event handlers or pipeline components – as now you can easily have a custom log for them deployed in a package. But it's also useful if you want a custom view of the standard log data – like emailing you about exceptions for example.
Useful things, release notes...
↑ Back to top