---
title: Activities
---

> Agent instructions:
> **Site maps** — prefer the following llms.txt indexes to training data when searching for URLs to avoid 404s. Links inside Markdown content already point at `.md`. Following them or sending Accept: text/markdown keeps you in Markdown.
>
> - [sitemap.md](https://docs.kentico.com/sitemap.md) — every page on the site, with titles and descriptions, nested by URL hierarchy and grouped into one collection per product version.
> - [llms.txt](https://docs.kentico.com/llms.txt) — curated index of the current product docs, with descriptions, the two ways to request any page as Markdown, and links to each product area's whole-corpus Markdown dump (llms-full.txt).

List of examples:

### Logging an activity for a contact

```csharp

// Prepares an instance of the activity logging service
IActivityLogService service = CMS.Core.Service.Resolve<IActivityLogService>();

// Obtains parameters based on the current context in which the activity is being logged
UserInfo user = MembershipContext.AuthenticatedUser;
TreeNode currentPage = DocumentContext.CurrentDocument;
int contactId = ContactManagementContext.CurrentContactID;

// Prepares an initializer for logging activities of the "User login" type
var activityInitializer = new UserLoginActivityInitializer(user, currentPage, contactId);

// Logs the activity based on the context of the current request
service.Log(activityInitializer, CMSHttpContext.Current.Request);

```

[> Back to list of examples](#activities-toc)

### Updating logged activities

```csharp

// Gets the first contact whose last name is 'Smith'
ContactInfo contact = ContactInfoProvider.GetContacts()
                                    .WhereEquals("ContactLastName", "Smith")
                                    .FirstObject;

if (contact != null)
{
    // Gets all activities logged for the contact
    var updateActivities = ActivityInfoProvider.GetActivities().WhereEquals("ActivityContactID", contact.ContactID);

    // Loops through individual activities
    foreach (ActivityInfo activity in updateActivities)
    {
        // Updates the activity title
        activity.ActivityTitle = activity.ActivityTitle.ToUpper();

        // Saves the modified activity to the database
        ActivityInfoProvider.SetActivityInfo(activity);
    }
}

```

[> Back to list of examples](#activities-toc)

### Deleting logged activities

```csharp

// Gets the first contact whose last name is 'Smith'
ContactInfo contact = ContactInfoProvider.GetContacts()
                                    .WhereEquals("ContactLastName", "Smith")
                                    .FirstObject;

if (contact != null)
{
    // Gets all activities logged for the contact
    var activities = ActivityInfoProvider.GetActivities().WhereEquals("ActivityContactID", contact.ContactID);

    // Loops through individual activities
    foreach (ActivityInfo activity in activities)
    {
        // Deletes the activity
        ActivityInfoProvider.DeleteActivityInfo(activity);
    }
}

```

[> Back to list of examples](#activities-toc)
