Neem contact op

Enrich your logging with Optimizely data

Senior Developer
Valtech Netherlands

februari 15, 2019

Tips for Optimizely logging

Some of you may have noticed I quite like Serilog ( And my NuGet package ( to integrate it in Optimizely is used quite a few times, so I guess I am not the only one.

One of the reasons I like it is that you enrich your logging with a lot of extra information.

There are quite a few enrichers available, but none for Optimizely specific things.

For example if you want to log the SiteId when an error occurs, you can create the following LogEventEnricher


public class SiteDataEnricher : ILogEventEnricher


    public const string SiteIdPropertyName = "SiteId";


    public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)


        if (logEvent == null)





        SiteDefinition siteDefinition = SiteDefinition.Current;


        if (siteDefinition.Id != Guid.Empty)



            new LogEventProperty(

            name: SiteIdPropertyName,

            value: new ScalarValue(value: SiteDefinition.Current.Id)));





I have created two NuGet packages enabling you to log

for CMS: Site Id, Site Name, Site Url, the serialized Content Data, Content Id and the Preferred Culture

for Commerce: the serialized Cart (if you call it default), current Contact Id, current Contact Name, current Contact Email, current Market


The complete code can be found on GitHub (

Or you can install the NuGet packages ( from the Optimizely feed.


If you have other things “log worthy” let me know, or add it to the modules on GitHub.


Original article was posted on Optimizely Development: Enrich your logging with Optimizely data 


Neem contact op

Let's reinvent the future