using Microsoft.Extensions.Logging; public class MyActor : Actor { private readonly ILogger _logger; public MyActor(ActorId actorId, ActorService actorService, ILoggerFactory loggerFactory) : base(actorId, actorService) { _logger = loggerFactory.CreateLogger(); } protected override async Task OnActivateAsync() { // Log a message _logger.LogInformation("Actor activated."); } }
public class MyActor : Actor, IRemindable { public async Task ReceiveReminderAsync(string reminderName, byte[] state, TimeSpan dueTime, TimeSpan period) { // Perform some action when the reminder fires } public async Task SetReminderAsync(string reminderName, byte[] state, TimeSpan dueTime, TimeSpan period) { ActorEventSource.Current.Message($"Setting reminder {reminderName}"); await RegisterReminderAsync(reminderName, state, dueTime, period); } }Here, we're implementing the IRemindable interface, which allows our actor to process reminders. We can use the RegisterReminderAsync method to create and register a new reminder, and respond to reminders when they fire. The package for context actor in C# is 'Microsoft.ServiceFabric.Actors.Runtime'. This package provides the Context Actor base class and various other classes and interfaces that enable actor programming in the Service Fabric environment.