This page describes how to add an activity log by code, which will show up on the order timeline
Activity logs are useful when you want to see what happened to an order straight from the order view, without the need to search through application logs. Another advantage over the application logs is that activity logs are persisted.
By default, Litium adds essential activity logs pertaining to the fulfilment process, but there are cases where you might want to add your own activity logs for other important order-related activities, such as interactions with the ERP.
Below, you will see an example of how to add a custom activity log through code in two different ways:
_eventBroker.Subscribe<SalesOrderConfirmed>(x =>
{
_mailService.SendEmail(new OrderConfirmationEmail(x.Item.ChannelSystemId.Value, x.SystemId, x.Item.CustomerInfo.Email), false);
// Untranslated activity log that will always appear as-is, regardless of UI language
_activityLogService.Add<Sales.Order>(x.SystemId, new ActivityLogArgs(OrderMessageTypes.SimpleMessage,
descriptionFields: new()
{
// For this message type, the message description field is the only mandatory field.
// It represents the message that will be displayed in the timeline.
["message"] = "The order confirmation email has been sent to {email}",
// Any other field in the description fields, such as email in this example,
// will be used to replace placeholders in the message, delimited by curly braces.
// There can be zero, one or multiple placeholders, where the field name must match the placeholder name.
["email"] = x.Item.CustomerInfo.Email
},
// Additional fields are optional. If they are provided, they will show under the activity log as collapsed,
// where they can be expanded from the UI.
additionalFields: new() { ["customerNumber"] = x.Item.CustomerInfo.CustomerNumber }));
// Translated activity log where the translation can either come from resource files or a website text
_activityLogService.Add<Sales.Order>(x.SystemId, new ActivityLogArgs(OrderMessageTypes.TranslatedMessage,
descriptionFields: new()
{
// For this message type, the message description field is the only mandatory field.
// It represents the key for the message that will be displayed in the timeline.
// The translations of the message (either in the resx file or the website text) can contain placeholders
// that will be replaced using the other fields in the description fields.
// In this example, let's assume that the translations for 'order.emailsent' have an email placeholder:
// * en-US: The order confirmation email has been sent to {email}
// * sv-SE: Orderbekräftelsen har skickats till {email}
["message"] = "order.emailsent",
// Any other field in the description fields, such as email in this example,
// will be used to replace placeholders in the translation of the message, delimited by curly braces.
// There can be zero, one or multiple placeholders, where the field name must match the placeholder name.
["email"] = x.Item.CustomerInfo.Email
},
// Additional fields are optional. If they are provided, they will show under the activity log as collapsed,
// where they can be expanded from the UI.
additionalFields: new() { ["customerNumber"] = x.Item.CustomerInfo.CustomerNumber }));
});
At the moment, the two message types (simple and translated) are the only supported message types.
Below you can see the result of the code above, shown for the Swedish language:
