<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Logging for Script Based Datasources. in Active IQ Unified Manager Discussions</title>
    <link>https://community.netapp.com/t5/Active-IQ-Unified-Manager-Discussions/Logging-for-Script-Based-Datasources/m-p/102765#M18195</link>
    <description>&lt;P&gt;WFA3.0 bundles log4net DLL with the WFA installer, so you don't need to downalod it from Apache website. I've added the .dar file for WFA3.0 as well. &amp;nbsp;Minior change in code to find and add the path to log4net.all as a part of the code. This code will work for both default and non-default installation locations. Just copy-paste the Create Logger Code in your DS script.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;sinhaa&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;FONT color="#008000"&gt;###### Create the Logger Configuration   ######&lt;/FONT&gt;&lt;BR /&gt;
&lt;FONT color="#008000"&gt;#Load the assembley from your dll location&lt;/FONT&gt;
$PSScriptRoot = Split-Path $MyInvocation.MyCommand.Path -Parent
$dllLocation=$PSScriptRoot.Substring(0, $($PSScriptRoot.Length - 24)) + "PoSH\Modules\DataONTAP\log4net.dll"
[void][Reflection.Assembly]::LoadFrom($dllLocation)
&lt;FONT color="#008000"&gt;#Define your logging pattern. See more about it here: http://logging.apache.org/log4net/release/sdk/log4net.Layout.PatternLayout.html&lt;/FONT&gt;
$pattern="%d %w %-5p %c : %m%n"
&lt;FONT color="#008000"&gt;#Reset the log4net configuration&lt;/FONT&gt;
[log4net.LogManager]::ResetConfiguration()
&lt;FONT color="#008000"&gt;#Create the Logging file for every single Datasource based on the Hostname.&lt;/FONT&gt;
$DSHostName = Get-WfaRestParameter "host"
$logFile=$PSScriptRoot.Substring(0, $($PSScriptRoot.Length - 8)) + "\log\" + $DSHostName +".log"
New-Item -Path $logFile -type file -ErrorAction SilentlyContinue
&lt;FONT color="#008000"&gt;#Create the log4net config Appender&lt;/FONT&gt;
$Appender = new-object log4net.Appender.FileAppender
$Appender.File = $logFile
$Appender.Layout = new-object log4net.Layout.PatternLayout($pattern)
$Appender.Threshold = [log4net.Core.Level]::All
$Appender.ActivateOptions()
[log4net.Config.BasicConfigurator]::Configure($Appender)
&lt;BR /&gt;&lt;FONT color="#008000"&gt;#Create Logger for the DataSource Type Name. You can actually put anything&lt;BR /&gt;&lt;BR /&gt;&lt;FONT color="#000000"&gt;$FName = $MyInvocation.MyCommand.Name&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#000000"&gt;$DSName = $FName.Substring(0, ($FName.Length - 23))&lt;/FONT&gt;&lt;/FONT&gt;
$logg = [log4net.LogManager]::GetLogger("[$DSName]")

&lt;FONT color="#008000"&gt;####### Logger is Ready #########&lt;/FONT&gt;
$PersonFile = "./person.csv"
New-Item -Path $PersonFile -type file -Force
Add-Content $PersonFile ([Byte[]][Char[]] "`\N`tAron`tFinch`t011-12345678`n") -Encoding Byte
Add-Content $PersonFile ([Byte[]][Char[]] "`\N`tDavid`tWarner`t011-12345677`n") -Encoding Byte
Add-Content $PersonFile ([Byte[]][Char[]] "`\N`tSteven`tSmith`t011-12345676`n") -Encoding Byte

&lt;FONT color="#008000"&gt;#Now log whatever you want.&lt;/FONT&gt;
$logg.Info("This is an info mssage on Host: $DSHostName")
$logg.Debug("This is a debug message")
$logg.Warn("This is a warning message")
$logg.Error("this is an error Message")
$logg.Fatal("this is a fatal error Message: $dllLocation")&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 12 Apr 2017 02:00:17 GMT</pubDate>
    <dc:creator>sinhaa</dc:creator>
    <dc:date>2017-04-12T02:00:17Z</dc:date>
    <item>
      <title>Logging for Script Based Datasources.</title>
      <link>https://community.netapp.com/t5/Active-IQ-Unified-Manager-Discussions/Logging-for-Script-Based-Datasources/m-p/100049#M17645</link>
      <description>&lt;P&gt;&lt;STRONG&gt;Logging for Script Based Datasources.&lt;/STRONG&gt;&lt;BR /&gt;---------------&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Problem Statement:&lt;/STRONG&gt;&lt;BR /&gt;----------------&lt;BR /&gt;1. In WFA, the script based Datasource Types don't have Datasource specific logging mechanism the way command executions have in a workflow.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;2. The WFA Powershell logging cmdlet Get-WfaLogger doesn't serve me well here. All the log data for all acquistion&amp;nbsp;instances of all DataSources gets dumped into a common wfa.log with which apart from these log data has tons of other Java logs.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;3. The wfa.log is a common logging file for a number of WFA activities. It just has too much data from everywhere. Its massive file and searching/debugging for anything is very diffcilut.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;4. Its keeps getting archieved from time to time. This adds to the problem of digging out an execution instance specific log-data. One needs to hunt though multiple files.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Araprt from the above problems being solved, I wanted the following too:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1. Flexible and configurable logger for every single DataSource Type. I may not want one common logging configuration for all my Datasource Types.&lt;BR /&gt;2. Every single Data source instance for a given Datasource Type to have separate log files.&lt;BR /&gt;3. To be able to view the logs from WFA GUI.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;STRONG&gt;Solution:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;----------&lt;BR /&gt;WFA is a very flexible framework and allows multiple 3rd party powershell modules/snapins/dlls to be plugged in.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;EM&gt;Download Apache Log4net&lt;/EM&gt;&lt;/STRONG&gt;&lt;BR /&gt;-----&lt;BR /&gt;Log4net is a very good logger for .NET platform. Download it from here: &lt;A href="http://apache.bytenet.in//logging/log4net/binaries/log4net-1.2.13-bin-newkey.zip" target="_blank"&gt;http://apache.bytenet.in//logging/log4net/binaries/log4net-1.2.13-bin-newkey.zip&lt;/A&gt; . Extracting it will have show numerous files but we need only 1, the log4net.dll . You can use the one at log4net-1.2.13\bin\net\3.5\release for you .NET version 3.5&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;EM&gt;Configuring log4net&lt;/EM&gt;&lt;/STRONG&gt;&lt;BR /&gt;-----&lt;BR /&gt;Most configurations for log4net are based on a common configuration file. But this can't serve my purpose. I wanted flexible configuration for every Datasource Type. So I need to set the configurations in the powershell code.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Here is an example logger definition inside a DataSource Type code.&lt;/STRONG&gt;&lt;BR /&gt;-----&lt;/P&gt;&lt;P&gt;###### Create the Logger Configuration ######&lt;BR /&gt;#Load the assembley from your dll location&lt;BR /&gt;[void][Reflection.Assembly]::LoadFrom("C:\log4net\log4net.dll")&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;#Define your logging pattern. See more about it here: &lt;A href="http://logging.apache.org/log4net/release/sdk/log4net.Layout.PatternLayout.html" target="_blank"&gt;http://logging.apache.org/log4net/release/sdk/log4net.Layout.PatternLayout.html&lt;/A&gt;&lt;BR /&gt;$pattern="%d %w %-5p %c : %m%n"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;#Reset the log4net configuration&lt;BR /&gt;[log4net.LogManager]::ResetConfiguration()&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;#Create the Logging file for every single Datasource based on the Hostname.&lt;BR /&gt;$DSHostName = Get-WfaRestParameter "host"&lt;/P&gt;&lt;P&gt;$PSScriptRoot = Split-Path $MyInvocation.MyCommand.Path -Parent&lt;BR /&gt;$logFile=$PSScriptRoot.Substring(0, $($PSScriptRoot.Length - 8)) + "\log\" + $DSHostName +".log"&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;#Create the log4net config Appender&lt;BR /&gt;$Appender = new-object log4net.Appender.FileAppender&lt;BR /&gt;$Appender.File = $logFile&lt;BR /&gt;$Appender.Layout = new-object log4net.Layout.PatternLayout($pattern)&lt;BR /&gt;$Appender.Threshold = [log4net.Core.Level]::All&lt;BR /&gt;$Appender.ActivateOptions()&lt;BR /&gt;[log4net.Config.BasicConfigurator]::Configure($Appender)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;#Create Logger for the DataSource Type Name. You can actually put anything&lt;BR /&gt;$logg = [log4net.LogManager]::GetLogger("[Person Data source with logging]")&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;####### Logger is Ready #########&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;$PersonFile = "./person.csv"&lt;BR /&gt;New-Item -Path $PersonFile -type file -Force&lt;/P&gt;&lt;P&gt;Add-Content $PersonFile ([Byte[]][Char[]] "`\N`tAron`tFinch`t011-12345678`n") -Encoding Byte&lt;BR /&gt;Add-Content $PersonFile ([Byte[]][Char[]] "`\N`tDavid`tWarner`t011-12345677`n") -Encoding Byte&lt;BR /&gt;Add-Content $PersonFile ([Byte[]][Char[]] "`\N`tSteven`tSmith`t011-12345676`n") -Encoding Byte&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;#Now log whatever you want.&lt;BR /&gt;$logg.Info("This is an info message on Host: $DSHostName")&lt;BR /&gt;$logg.Debug("This is a debug message")&lt;BR /&gt;$logg.Warn("This is a warning message")&lt;BR /&gt;$logg.Error("this is an error Message")&lt;BR /&gt;$logg.Fatal("this is a fatal error Message")&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;###### END Code #############&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;To view the logs fom WFA GUI, go to WFA Administration -&amp;gt; Log Viewer . You'll see a log file with name as the name of the Data Source host ( e.g. Host01.log ). Now every single DataSource &amp;nbsp;belonging to this Datasource type will have separate log file.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="DS_log viewer.png" style="width: 834px;"&gt;&lt;img src="https://community.netapp.com/t5/image/serverpage/image-id/1961i6F64BC87D5E7EEC0/image-size/large?v=v2&amp;amp;px=999" role="button" title="DS_log viewer.png" alt="DS_log viewer.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="DS_log viewer 2.png" style="width: 955px;"&gt;&lt;img src="https://community.netapp.com/t5/image/serverpage/image-id/1962iB59BA85F09579825/image-size/large?v=v2&amp;amp;px=999" role="button" title="DS_log viewer 2.png" alt="DS_log viewer 2.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 05 Jun 2025 05:11:09 GMT</pubDate>
      <guid>https://community.netapp.com/t5/Active-IQ-Unified-Manager-Discussions/Logging-for-Script-Based-Datasources/m-p/100049#M17645</guid>
      <dc:creator>sinhaa</dc:creator>
      <dc:date>2025-06-05T05:11:09Z</dc:date>
    </item>
    <item>
      <title>Re: Logging for Script Based Datasources.</title>
      <link>https://community.netapp.com/t5/Active-IQ-Unified-Manager-Discussions/Logging-for-Script-Based-Datasources/m-p/102765#M18195</link>
      <description>&lt;P&gt;WFA3.0 bundles log4net DLL with the WFA installer, so you don't need to downalod it from Apache website. I've added the .dar file for WFA3.0 as well. &amp;nbsp;Minior change in code to find and add the path to log4net.all as a part of the code. This code will work for both default and non-default installation locations. Just copy-paste the Create Logger Code in your DS script.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;sinhaa&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;FONT color="#008000"&gt;###### Create the Logger Configuration   ######&lt;/FONT&gt;&lt;BR /&gt;
&lt;FONT color="#008000"&gt;#Load the assembley from your dll location&lt;/FONT&gt;
$PSScriptRoot = Split-Path $MyInvocation.MyCommand.Path -Parent
$dllLocation=$PSScriptRoot.Substring(0, $($PSScriptRoot.Length - 24)) + "PoSH\Modules\DataONTAP\log4net.dll"
[void][Reflection.Assembly]::LoadFrom($dllLocation)
&lt;FONT color="#008000"&gt;#Define your logging pattern. See more about it here: http://logging.apache.org/log4net/release/sdk/log4net.Layout.PatternLayout.html&lt;/FONT&gt;
$pattern="%d %w %-5p %c : %m%n"
&lt;FONT color="#008000"&gt;#Reset the log4net configuration&lt;/FONT&gt;
[log4net.LogManager]::ResetConfiguration()
&lt;FONT color="#008000"&gt;#Create the Logging file for every single Datasource based on the Hostname.&lt;/FONT&gt;
$DSHostName = Get-WfaRestParameter "host"
$logFile=$PSScriptRoot.Substring(0, $($PSScriptRoot.Length - 8)) + "\log\" + $DSHostName +".log"
New-Item -Path $logFile -type file -ErrorAction SilentlyContinue
&lt;FONT color="#008000"&gt;#Create the log4net config Appender&lt;/FONT&gt;
$Appender = new-object log4net.Appender.FileAppender
$Appender.File = $logFile
$Appender.Layout = new-object log4net.Layout.PatternLayout($pattern)
$Appender.Threshold = [log4net.Core.Level]::All
$Appender.ActivateOptions()
[log4net.Config.BasicConfigurator]::Configure($Appender)
&lt;BR /&gt;&lt;FONT color="#008000"&gt;#Create Logger for the DataSource Type Name. You can actually put anything&lt;BR /&gt;&lt;BR /&gt;&lt;FONT color="#000000"&gt;$FName = $MyInvocation.MyCommand.Name&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#000000"&gt;$DSName = $FName.Substring(0, ($FName.Length - 23))&lt;/FONT&gt;&lt;/FONT&gt;
$logg = [log4net.LogManager]::GetLogger("[$DSName]")

&lt;FONT color="#008000"&gt;####### Logger is Ready #########&lt;/FONT&gt;
$PersonFile = "./person.csv"
New-Item -Path $PersonFile -type file -Force
Add-Content $PersonFile ([Byte[]][Char[]] "`\N`tAron`tFinch`t011-12345678`n") -Encoding Byte
Add-Content $PersonFile ([Byte[]][Char[]] "`\N`tDavid`tWarner`t011-12345677`n") -Encoding Byte
Add-Content $PersonFile ([Byte[]][Char[]] "`\N`tSteven`tSmith`t011-12345676`n") -Encoding Byte

&lt;FONT color="#008000"&gt;#Now log whatever you want.&lt;/FONT&gt;
$logg.Info("This is an info mssage on Host: $DSHostName")
$logg.Debug("This is a debug message")
$logg.Warn("This is a warning message")
$logg.Error("this is an error Message")
$logg.Fatal("this is a fatal error Message: $dllLocation")&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 12 Apr 2017 02:00:17 GMT</pubDate>
      <guid>https://community.netapp.com/t5/Active-IQ-Unified-Manager-Discussions/Logging-for-Script-Based-Datasources/m-p/102765#M18195</guid>
      <dc:creator>sinhaa</dc:creator>
      <dc:date>2017-04-12T02:00:17Z</dc:date>
    </item>
  </channel>
</rss>

