Kentico CMS 7.0 Developer's Guide

LogChange handler

LogChange handler

Previous topic Next topic Mail us feedback on this topic!  

LogChange handler

Previous topic Next topic JavaScript is required for the print function Mail us feedback on this topic!  

By default, Kentico logs changes that you make to objects and documents. You can use the LogChange handler to affect logging of these changes for tasks such as staging or integration.

 

Excluding documents

 

In the following example, you can see the use of the LogChange handler to exclude documents contained under the "/Home" path from staging.

 

Fore more information on registering handlers, visit the Global events topic.

 

[C#]

 

using System;

 

using CMS.DocumentEngine;

using CMS.SettingsProvider;

 

/// <summary>

/// Exclude documents under '/Home' path from staging.

/// </summary>

[CustomDocumentEvents]

public partial class CMSModuleLoader

{

  /// <summary>

  /// Ensure the loading of custom handlers

  /// </summary>

  private class CustomDocumentEventsAttribute : CMSLoaderAttribute

   {

      /// <summary>

      /// Called automatically when the application starts

      /// </summary>

      public override void Init()

       {

          // Assign custom handlers to the appropriate events

          DocumentEvents.LogChange.Before += new EventHandler<LogDocumentChangeEventArgs>(LogDocumentChange_Before);

       }

 

      void LogDocumentChange_Before(object sender, LogDocumentChangeEventArgs e)

       {

          var document = e.Settings.Node;

          if (document.NodeAliasPath.StartsWith("/Home"))

           {

               e.Settings.LogStaging = false;

           }

       }

   }

}

 

Excluding objects

 

In the following example, you can see the use of the LogChange handler to exclude objects of the object type "role" whose code name starts with "CMS" from staging.

 

Fore more information on registering handlers, visit the Global events topic.

 

[C#]

 

using System;

 

using CMS.SettingsProvider;

 

/// <summary>

/// Exlude objects of the object type 'role' whose code name starts with 'CMS' from staging.

/// </summary>

[CustomObjectEvents]

public partial class CMSModuleLoader

{

  /// <summary>

  /// Ensure the loading of custom handlers

  /// </summary>

  private class CustomObjectEventsAttribute : CMSLoaderAttribute

   {

      /// <summary>

      /// Called automatically when the application starts

      /// </summary>

      public override void Init()

       {

          // Assign custom handlers to the appropriate events

          ObjectEvents.LogChange.Before += new EventHandler<LogObjectChangeEventArgs>(LogObjectChange_Before);

       }

 

      void LogObjectChange_Before(object sender, LogObjectChangeEventArgs e)

       {

          var obj = e.Settings.InfoObj;

          if ((obj.ObjectType == PredefinedObjectType.ROLE) && (obj.ObjectCodeName.StartsWith("CMS")))

           {

               e.Settings.LogStaging = false;

           }

       }

   }

}