---
title: Configure a notification listener using the C# SDK
slug: feature-experimentation/docs/set-up-notification-listener-csharp
docTags: 
createdAt: 2026-08-05T20:40:02.000Z
---

Notification listeners trigger a callback function that you define when certain actions are triggered in the SDK.

The most common use case is to send a stream of all feature flag decisions to an analytics provider or to an internal data warehouse to join it with other data that you have about your users.

## Notification listener types

For information about notification listener types and use cases, see [Notification listeners](docId:0d__cjuKECyJGqgTV0_5e).

## Add and remove all notification listeners

The following example code shows how to add a listener, remove a listener, remove all listeners of a specific type (such as all decision listeners), and remove all listeners.

```csharp
using OptimizelySDK;
using NotificationType = OptimizelySDK.Notifications.NotificationCenter.NotificationType;

var datafile = "YOUR_JSON_DATAFILE";
var optimizely = new Optimizely(datafile);

// Remove notification listener
optimizely.NotificationCenter.RemoveNotification(notificationId);

// Clear all notification listeners of a certain type
optimizely.NotificationCenter.ClearNotifications(NotificationType.Decision);

// Clear all notifications
optimizely.NotificationCenter.ClearAllNotifications();
```

## Configure each type of notification listener

The following example code shows how to configure each type of notification listener.

```csharp
using OptimizelySDK;
using OptimizelySDK.Entity;
using OptimizelySDK.Event;
using OptimizelySDK.Notifications;
using NotificationType = OptimizelySDK.Notifications.NotificationCenter.NotificationType;

// import your third-party analytics integration here

var datafile = "YOUR_JSON_DATAFILE";
var optimizely = new Optimizely(datafile);

/*
 * Set up decision notification listener to get notified of any decision event
 */
NotificationCenter.DecisionCallback OnDecision = (type, userId, userAttributes, decisionInfo) =>
{
    // Access type on decisionObject to get type of decision
    if (type == "flag")
    {
        var serializedJsonInfo = Newtonsoft.Json.JsonConvert.SerializeObject(decisionInfo);
        Console.WriteLine($"Feature flag access related information: {serializedJsonInfo}");
        // Send data to analytics provider here
    }
};

// Add/register the notification listener using the notificationId to remove the listener later
var notificationId =
    optimizely.NotificationCenter.AddNotification(NotificationType.Decision, OnDecision);

/*
 * Set up log event notification listener to get notified of any log events
 */
NotificationCenter.LogEventCallback OnLogEvent = (logEvent) =>
{
    // process the logEvent object here (send to analytics provider, audit/inspect data)
};

// Add/register the notification listener using the notificationId to remove the listener later
var notificationId =
    optimizely.NotificationCenter.AddNotification(NotificationType.LogEvent, OnLogEvent);

/*
 * Set up config update notification listener to get notified of any datafile updates
 * except during SDK initialization
 */
NotificationCenter.OptimizelyConfigUpdateCallback OnConfigUpdate = () =>
{
    // Use the optimizely instance to get the updated config
    var optimizelyConfig = optimizely.GetOptimizelyConfig();
};

// Add/register the notification listener using the notificationId to remove the listener later
var notificationId =
    optimizely.NotificationCenter.AddNotification(NotificationType.OptimizelyConfigUpdate,
        OnConfigUpdate);

/*
 * Set up track notification listener to get notified of any track event calls
 */
NotificationCenter.TrackCallback OnTrack =
    (string eventKey, string userId, UserAttributes userAttributes, EventTags eventTags,
        LogEvent logEvent) =>
    {
        // process the event here (send to analytics provider, audit/inspect data)
    };

// Add/register the notification listener using the notificationId to remove the listener later
var notificationId = optimizely.NotificationCenter.AddNotification(NotificationType.Track, OnTrack);
```
