Monitoring Workflow events

I received lots of questions in the past about problems with workflow events. To understand what can be done in a workflow event it is helpful to know the sequence the events are fired during save, approve and any other action.

The code below can be added to the global.asax.cs and will then track all workflow events to a text file. For each event some additional information is also added to the log. If you already have workflow events in place add the LogEvent routine to your global.asax.cs and copy the single line from my events into your own event handler.

  FileStream fsLog = null;
  StreamWriter wLog = null;

  public void LogEvent(String Method, Object o)
  {
     fsLog = new FileStream(“c:\\SlgLog.txt”,FileMode.Append,FileAccess.Write);
     wLog = new StreamWriter(fsLog);
     wLog.WriteLine(“——————————————————-“);
     wLog.WriteLine(System.DateTime.Now.ToString()+” – “+
                    Method);

     wLog.WriteLine(” – e (Type) “+o.GetType().ToString());

     if (o is PublishingEventArgs)
     {
        PublishingEventArgs e = (PublishingEventArgs) o;
        wLog.WriteLine(” – e.Action: “+e.Action.ToString());
        wLog.WriteLine(” – e.Target (Type): “+e.Target.GetType().ToString());

        if (e.Target is Placeholder)
        {
           Placeholder ph = (Placeholder)e.Target;
           wLog.WriteLine(” – Placeholder: “+ph.Name);
           if (ph is HtmlPlaceholder)
           {
              HtmlPlaceholder htmlph = (HtmlPlaceholder)ph;
              wLog.WriteLine(” – Placeholder (Content): “+htmlph.Html);
           }
           wLog.WriteLine(” – Posting: “+ph.Posting.Path+” – State: “+
                          ph.Posting.State);
        }

        if (e.Target is Posting)
        {
           Posting p = (Posting)e.Target;
           wLog.WriteLine(” – Posting: “+p.Path+” – State: “+p.State);

           foreach (User Approver in p.Approvers(true))
           {
              wLog.WriteLine(” – Approver: “+Approver.ClientAccountName);
           }
  //       if ((Method == “CmsPosting_Approving”) ||
  //           (Method == “CmsPosting_Approved”))
  //       {
  //          wLog.WriteLine(” -0 LastApprovedDeclinedBy: “+p.LastApprovedDeclinedBy);
  //          wLog.WriteLine(” -0 LastModifiedBy: “+p.LastModifiedBy);
  //          wLog.WriteLine(” -0 LastModifiedDate: “+p.LastModifiedDate);
  //          e.Context.CommitAll();
  //          wLog.WriteLine(” -1 LastApprovedDeclinedBy: “+p.LastApprovedDeclinedBy);
  //          wLog.WriteLine(” -1 LastModifiedBy: “+p.LastModifiedBy);
  //          wLog.WriteLine(” -1 LastModifiedDate: “+p.LastModifiedDate);
  //       }
        }
     }
   
     wLog.Flush();
     wLog.Close();
     fsLog.Close();
  }

  public void CmsPosting_Approved( Object sender, ChangedEventArgs e )
  {
     LogEvent(“CmsPosting_Approved”,e);
  }

  public void CmsPosting_Approving( Object sender, ChangingEventArgs e )   
  {
     LogEvent(“CmsPosting_Approving”,e);
  }

  public void CmsPosting_Changed( Object sender, ChangedEventArgs e )   
  {
     LogEvent(“CmsPosting_Changed”,e);
  }

  public void CmsPosting_Changing( Object sender, ChangingEventArgs e )   
  {
     LogEvent(“CmsPosting_Changing”,e);
  }

  public void CmsPosting_Created( Object sender, CreatedEventArgs e )   
  {
     LogEvent(“CmsPosting_Created”,e);
  }

  public void CmsPosting_Creating( Object sender, CreatingEventArgs e )   
  {
     LogEvent(“CmsPosting_Creating”,e);
  }

  public void CmsPosting_CustomPropertyChanged( Object sender, Microsoft.ContentManagement.Publishing.Events.PropertyChangedEventArgs e )   
  {
     LogEvent(“CmsPosting_CustomPropertyChanged”,e);
  }

  public void CmsPosting_CustomPropertyChanging( Object sender, PropertyChangingEventArgs e )   
  {
     LogEvent(“CmsPosting_CustomPropertyChanging”,e);
  }

  public void CmsPosting_Declined( Object sender, ChangedEventArgs e )   
  {
     LogEvent(“CmsPosting_Declined”,e);
  }

  public void CmsPosting_Declining( Object sender, ChangingEventArgs e )   
  {
     LogEvent(“CmsPosting_Declining”,e);
  }

  public void CmsPosting_Deleted( Object sender,  ChangedEventArgs e )   
  {
     LogEvent(“CmsPosting_Deleted”,e);
  }

  public void CmsPosting_Deleting( Object sender, ChangingEventArgs e )   
  {
     LogEvent(“CmsPosting_Deleting”,e);
  }

  public void CmsPosting_Moved( Object sender, MovedEventArgs e )   
  {
     LogEvent(“CmsPosting_Moved”,e);
  }

  public void CmsPosting_Moving( Object sender, MovingEventArgs e )   
  {
     LogEvent(“CmsPosting_Moving”,e);
  }

  public void CmsPosting_PlaceholderPropertyChanged( Object sender, Microsoft.ContentManagement.Publishing.Events.PropertyChangedEventArgs e )   
  {
     LogEvent(“CmsPosting_PlaceholderPropertyChanged”,e);
  }

  public void CmsPosting_PlaceholderPropertyChanging( Object sender, PropertyChangingEventArgs e )   
  {
     LogEvent(“CmsPosting_PlaceholderPropertyChanging”,e);
  }

  public void CmsPosting_PropertyChanged( Object sender, Microsoft.ContentManagement.Publishing.Events.PropertyChangedEventArgs e )   
  {
     LogEvent(“CmsPosting_PropertyChanged”,e);
  }

  public void CmsPosting_PropertyChanging( Object sender, PropertyChangingEventArgs e )   
  {
     LogEvent(“CmsPosting_PropertyChanging”,e);
  }

  public void CmsPosting_Submitted( Object sender, ChangedEventArgs e )
  {
     LogEvent(“CmsPosting_Submitted”,e);
  }

  public void CmsPosting_Submitting( Object sender, ChangingEventArgs e )   
  {
     LogEvent(“CmsPosting_Submitting”,e);
  }

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.