🚀 Welcome to MDriven Learn –  Don’t miss the latest Release Notes.
Logging OCL in Turnkey


Expand your TK app with your own OCL logging if you are using CodeDress. This will work and have the same features as the Designer's built-in logging.

Create a transient and singleton class like this:

Add code similar to the code at the bottom of this page to the class methods. Create a ViewModel like the example below to use the class:

I created a variable on the view with the name vLogText.

The GetLog action does this:

vLogText := self.GetLog

The GetUsageStats action does this:

vLogText := self.GetUsageStats

The method SO() is a shortcut for:

SysLogging.oclSingleton

Code for the class:

 public partial class SysLogging
   {
     StringBuilder sb = new StringBuilder(100000);
     void Singleton_OnTraceLog(object sender, Eco.Logging.TraceEventArgs e)
     {
       if (sb.Length > 5000000)
         sb.Clear();
       sb.AppendLine(e.Message);
     }
 
     [UmlElement(Id = "ee54deb5-3024-47c2-be01-7c93faa6638a")]
     public void StartLogging()
     {
       this.StopLogging();
       EcoLogSwitches.LogOcl = this.LogOcl;
       EcoLogSwitches.LogEAL = this.LogEAL;
       EcoLogSwitches.LogPMapper = this.LogPMapper;
       EcoLogSwitches.LogSql = this.LogSql;
       EcoLogSwitches.LogSqlMeta = this.LogSqlMeta;
       EcoLogSwitches.LogActionExecute = this.LogActionExecute;
       EcoLogSwitches.LogActionEnable = this.LogActionEnable;
       EcoLogSwitches.LogMethods = this.LogMethods;
       EcoLogSwitches.CollectAssociationUsageStats = this.CollectAssociationUsageStats;
       EcoLogSwitches.LogWecpof = this.LogWecpof;
 
       EcoListener.Singleton.OnTraceLog += Singleton_OnTraceLog;
       EcoListener.StartListening();
     }
 
     [UmlElement(Id = "ace10ea6-8793-4205-a2eb-9f22b9391701")]
     public string GetLog()
     {
       string text = sb.ToString();
       sb.Clear();
       return text;
     }
 
     [UmlElement(Id = "3d2941f2-75ca-4a41-a5e8-465ddcfa2904")]
     public void StopLogging()
     {
       EcoListener.Singleton.OnTraceLog -= Singleton_OnTraceLog;
       Eco.Logging.EcoListener.StopListening();
     }
 
     [UmlElement(Id = "a4e7d189-a056-4be4-8e07-ea42d72505ac")]
     public string GetUsageStats()
     {
       StringBuilder stats = new StringBuilder();
       lock (EcoSupport.AssociationUsageStats)
       {
         if (EcoSupport.AssociationUsageStats.Count > 0)
         {
           foreach (KeyValuePair<string, int> x in EcoSupport.AssociationUsageStats)
           {
             stats.AppendLine(x.Key + " = " + x.Value.ToString());
           }
         }
         else
           stats.AppendLine("No stats in log");
       }
       return stats.ToString();
     }
   }
}

See also: Logging what MDriven does

Keywords: debugging OCL, logging, performance