Quantcast
Channel: PowerShell App Deployment Toolkit
Viewing all articles
Browse latest Browse all 2341

Closed Unassigned: Write-log: logfilename parameter not working [125]

$
0
0

I just notice when appdeploytoolkit is load then it is creating variables. If later in a script we need writing to a different log using -logfilename then there is no way to change the log. So the -logfilename is useless. :(


```
Set-StrictMode -off
[string]$scriptDirectory = Split-Path -Path $MyInvocation.MyCommand.Definition -Parent # Emplacement du script
[string]$moduleAppDeployToolkitMain = "$scriptDirectory\_Include\AppDeployToolkit\AppDeployToolkitMain.ps1"
. $moduleAppDeployToolkitMain
Write-Log "test" -LogFileName "test.log"

```
The problem seem coming from:

```
____ If (-not (Test-Path -Path 'variable:OutLogFile')) {## Upon first execution of below If block, script variable is created so this block is not executed more than once.

# Create the directory where the log file will be saved
If (-not (Test-Path -Path $LogFileDirectory -PathType Container)) {
Try {
New-Item -Path $LogFileDirectory -Type 'Directory' -Force -ErrorAction 'Stop' | Out-Null
}
Catch {
# If error creating directory, write message to console
If (-not $ContinueOnError) {
Write-Host "[$LogDate $LogTime] [${CmdletName}] $ScriptSection :: Failed to create the log directory [$LogFileDirectory]. `n$(Resolve-Error)" -ForegroundColor 'Red'
}
Return
}
}

# Assemble the fully qualified path to the log file
[string]$LogFilePath = Join-Path -Path $LogFileDirectory -ChildPath $LogFileName

# Set variable so that this 'If' block is not executed again during the execution of this script
__ Set-Variable -Name 'OutLogFile' -Value $LogFilePath -Scope 'Script'__
}

In fact, If a user is providing a different log than the default one then the different log should be use.
```

Am I right?

Thanks,

Comments: Thanks, sounds good. If there are any more issues, just reopen the ticket.

Viewing all articles
Browse latest Browse all 2341

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>