Writing To Log Files
  • 09 Jul 2024
  • 3 Minutes to read
  • Dark
    Light

Writing To Log Files

  • Dark
    Light

Article summary

Overview

One benefit provided by Logging in Decisions is the ability for Users to write to the Logs from their code, by first instantiating a DecisionsFramework.Log. Doing so will allow users to write to the Logs at different Levels.

Many of these Levels have the same Input Data but provide different functions. The following document explains how to access the Logs, the differences between various Logging Types, and provides a deployable code example that provides a method to test writing to Logs. 


Accessing Logs

The Decisions Logs can be accessed through the following two ways: 

  • By opening the .log files directly; this file is stored at C:\Program Files\Decisions\Decisions Server\Logs

  • By navigating to System > Administration > System Tools > Logging.

Logging Types

The following chart represents the various types of Logs that can be viewed in the Logging Folder or System Logs file and a brief description on each one. 

Log TypeDescription
Assembly Types Parser AppDomain.logThis is the Log for Assembly Types that are Parsed in the App Domain. This is generally not enabled but it seems like that the Configuration was set to Log to its own file.
DecisionsServiceHost.exe.* .logThis file contains the Log for the Main Service (i.e. the Windows Service that is Installed)
DecisionsServiceHost.exe.Usage.* .csvThis File contains the Usage Log, Memory details, counts etc. for Host Service
DecisionsServiceHost.exe.UsageDetails.* .logThis File contains the Usage Log, Memory details, counts etc. for Host Service (Individual Calls and Additional Details)
DecTail.exeCustom tailing application.
Primary.* .logLog messages from the Decisions Service Host Manager. - Primary Instance
Primary.Usage.* .csvMinute-by-minute logs of Flow executions, API calls, job executions, etc. - Primary Instance
Primary.UsageDetails.* .logMinute-by-minute counts of individual API calls, Flows runs, etc. - Primary Instance
View_Usage_CSV.ps1 & View_Usage_Text.ps1These are PowerShell scripts to open the usage logs in PowerShell.
WebSite_HUI.log & WebSite_decisions.logThese are more the construction of the website within IIS rather that Decisions that is hosted within. These are depreciated in newer versions.

Input Data Chart 

The following chart displays the Input Data used by these Levels and how that data is used in the Logs.

Input NameFunction 
object sourceObjectThe Logger will attempt to do a ToString() on the object and write that String in the Log entry.
string messageThis is the main part of a Log message. Users can write custom text here to signal where in the code they are.
params object[] argumentsThis allows users Input Parameter into their Log message. For example, a Log entry may be written like this: LogDebug(this,"{0} {1} {2} is today", "Thursday", "Jan 10th", "2013");

Example

The code box below explains each of the different Levels found by default in Decisions.

The attached Project File contains this code and can be compiled/deployed as a step to allow the testing of different combinations with each Logging Level

   WriteToLogFile  

 using DecisionsFramework;
using System;
using DecisionsFramework.Design.Flow;
 
namespace DecisionsLoggingSample
{
  [AutoRegisterMethodsOnClass(true, "SampleSteps", "Logging", RegisterForAgents = true)]
  public class LoggingExample
  {
    //Note: the name (e.g. "Example Log") provided here will prefix the logs
    //that is written with this instance of Log.
    //For example an info level log written with this Log will look like the following:
    //[Info],09 Jan 2013 16:39:11,Thread 23,Exmaple Log [Message]:Info level message
    private static Log log = new Log("Example Log");
 
    public static void writeToDecisionsLogs()
    {       
      //create an exception we can use in logging
      try
      {
        int zero = 0;
        int number = 5 / zero;
      }
      catch (Exception ex)
      {
        //The Info, Debug and Warn levels are very similar.
        //They take the same inputs and using one instead of the other
        //just changes the level at which the log is written.
        //Currently the first (object) parameter is not used in these levels and can be set to null.
        //Looks like: [Info],14 Jan 2013 11:12:05,Thread 17,Example Log [Message]:Info level message. Today is Thursday Jan 10th 2013
        log.LogInfo(null, "Info level message. Today is {0} {1} {2}", "Thursday", "Jan 10th", "2013");
         
        //Looks like: [Debug],14 Jan 2013 11:12:05,Thread 17,Example Log [Message]:Debug level message
        log.LogDebug(null, "Debug level message");
 
        //Looks like: [Warn],14 Jan 2013 11:12:05,Thread 17,Example Log [Message]:Warm level message
        log.LogWarn(null, "Warm level message");
 
 
 
        //LogError can be used in three ways. This level does use the object input parameter and so can be set to null or to a value;
        //Looks like: [Error],14 Jan 2013 11:12:05,Thread 17,Example Log [Message]:Error level message
        log.LogError(null, "Error level message");
 
        //Looks like: [Error],14 Jan 2013 11:12:05,Thread 17,Example Log [Message]:Attempted to divide by zero. [Exception]:System.DivideByZeroException: Attempted to divide by zero.  at DecisionsLoggingSample.LoggingExample.writeToDecisionsLogs()
        log.LogError(null, ex);
         
        //Looks like: [Error],14 Jan 2013 11:12:05,Thread 17,Example Log [Message]:Error level message [Exception]:System.DivideByZeroException: Attempted to divide by zero.  at DecisionsLoggingSample.LoggingExample.writeToDecisionsLogs()
        log.LogError(null, ex, "Error level message");
 
 
 
        //Currently the first (object) parameter is not used in these levels and can be set to null.
        //Looks like: [Fatal],14 Jan 2013 11:12:05,Thread 17,Example Log [Message]:Fatal level message [Exception]:System.DivideByZeroException: Attempted to divide by zero.  at DecisionsLoggingSample.LoggingExample.writeToDecisionsLogs()
        log.LogFatal(null, "Fatal level message", ex);
 
        //Looks like: [Fatal],14 Jan 2013 11:12:05,Thread 17,Example Log [Message]:Fatal level message
        log.LogFatal(null, "Fatal level message");
      }
    }
  }
}

For further information on Settings, visit the Decisions Forum.

Was this article helpful?