December 2014 archive

What branch is on which environment?

There is an easy way to keep tabs about what code is on each environment. There is a good MSBuild project which provides a set of useful additional MSBuild tasks:

https://github.com/loresoft/msbuildtasks

To reference the extra tasks, you will need to make sure you have referenced the MSBuild Community Tasks Project DLL. The tasks of interest are GitVersion and GitBranch which will provide details of the SHA and branch that is being deployed. The following target is what you need to get started:

This will generate a file to App_Config/__DeployInfo which will look something like:

Similar functionality could be added for Mercurial but isn’t included in this project, the following could be useful: https://msbuildhg.codeplex.com/documentation

Logging to a Database with Log4Net

If you need to log to a database instead of a text file, you can use Log4Net to do it by just changing some config: http://sitecoreblog.alexshyba.com/2010/07/sitecore-logging-write-it-to-sql.html

If you want to only log a small number of things to the database (but still log everything else to the existing log), then instead of adding the sql adonet appender to the main root logger in the config, create a new logger node and add the sql ado appender to that. Eg:

<logger name=”PublishLog” additivity=”false”>
<level value=”INFO”/>
<appender-ref ref=”ADONetAppender_PublishedItems”/>
</logger>

Then when logging, explicitly use this logger using the Sitecore Logger Factory. Eg: “Sitecore.Diagnostics.LoggerFactory.GetLogger(“PublishLog”)”