How to: Log to the History List from a Workflow Activity

Overview

When you create custom full-trust workflow activities for Microsoft® SharePoint® solutions, you might often want to add entries to the Workflow History list on your SharePoint site. This how-to topic describes how to log to the History list from a workflow activity class.

Ff798337.note(en-us,PandP.10).gifNote:
This how-to topic assumes that you have already created a workflow activity class that derives from the System.Workflow.ComponentModel.Activity base class. For more information about creating a custom workflow activity, see the Workflow Activities reference implementation.

Steps

To log to the history list from a workflow activity

  1. Locate the Execute method in your workflow activity class.
    protected override ActivityExecutionStatus Execute(ActivityExecutionContext 
                                                 executionContext) 
    { 
      // The activity logic goes here.
      return base.Execute(executionContext);
    }
    
    
  2. In the Execute method, retrieve an implementation of the ISharePointService interface from the execution context object.
    ISharePointService wfService = 
      executionContext.GetService<ISharePointService>();
    
    
  3. On the ISharePointService implementation, call the LogToHistoryList method.
    wfService.LogToHistoryList(executionContext.ContextGuid, 
      SPWorkflowHistoryEventType.WorkflowComment, 
      0, 
      TimeSpan.Zero, 
      "Information", 
      "Logged via ISharePointService", 
      string.Empty);
    
    

    The LogToHistoryList method will create an entry in the Workflow History list that corresponds to the execution context of the workflow.



Show: