Using built-in logging for Biml

Written by Roelant Vos on 8.26.2021

TAGS: Biml,adf,Logging

Share

When working with Biml in any situation, be it using BimlExpress, BimlStudio or BimlFlex, it can be helpful to peek into what is happening in the background.

Some of you would have developed your own metadata framework that provides information to generate Biml, created a solution in BimlStudio or added extensions for BimlFlex. In all cases, it is possible to add logging to your solution and this is already natively available in BimlScript.

There is no need to create your own logging framework if the Biml logging already meets your needs, and it covers most common scenarios. The standard logging can write to a text buffer, an object such as a list, a file or it can trigger an event.

Working with logging is covered in detail in The Biml Book, and it is worth having a look especially if you are using BimlExpress.

But it is also possible to add logging to BimlStudio right away with just a few lines of code, with the immediate benefit that the log messages appear in the logging pane.

Make sure you enable the logging function in BimlStudio for this. This can be found in the ‘Build & Deploy’ menu.

To get started, add the Varigence Utility Logging reference to you script, and give the below code a try. This simple example creates a List of string values that are meant to be used to generate DataFactory Biml.

For each iteration, a log is written to the logging pane.

<#@ import namespace="Varigence.Utility.Logging" #>
<#
   LoggingManager.TryDefaultLog($"Info", "BimlScript", $"Getting started.");
   List<string> datafactories = new List<string>(new string[] { "MyNewDataFactory", "TheBestDataFactory" });
   LoggingManager.TryDefaultLog($"Info", "BimlScript", "Getting started...");
#>
<Biml xmlns="http://schemas.varigence.com/biml.xsd">
   <DataFactories>
      <#
      foreach (string datafactory in datafactories)
      {
      #>
      <DataFactory Name="<#=datafactory#>">
         <#LoggingManager.TryDefaultLog($"Info", "BimlScript", $"Hey, I just added {datafactory}!");#>
      </DataFactory>
      <#
      }
      #>
   </DataFactories> 
</Biml>

The result looks like the screenshot below. Happy logging!

alt text here…

Comments