ps/Modules/Alkami.PowerShell.Configuration/Public/Copy-AlkamiLog4net.ps1

46 lines
1.6 KiB
PowerShell
Raw Permalink Normal View History

2023-05-30 22:51:22 -07:00
function Copy-AlkamiLog4net {
<#
.SYNOPSIS
Renames staged log4net.config files to new.log4net.config if there isn't already one in the build output
Deletes staged log4net.config files if there's already a new.log4net.config file in the build output
.NOTES
I'm not a fan of this verb but I don't know everywhere this function might be called so I'm leaving it
#>
[CmdletBinding()]
Param(
[Parameter(Mandatory = $false)]
[string]$TempPath = "C:\temp\deploy\"
)
$logLead = Get-LogLeadName
Write-Host ("$logLead : Looking for Subfolders Under Directory {0}" -f $TempPath)
$orbFolders = Get-ChildItem $TempPath | Where-Object { $_.PsIsContainer } | Select-Object -ExpandProperty FullName
foreach ($orbFolder in $orbFolders) {
$log4netConfig = Get-ChildItem $orbFolder | Where-Object { $_.Name -eq "log4net.config" } | Select-Object -ExpandProperty FullName
if ($null -ne $log4netConfig -and $log4netConfig.Count -gt 0) {
$newLogConfig = Join-Path (Split-Path $log4netConfig) "new.log4net.config"
if (Test-Path $newLogConfig) {
Write-Host ("$logLead : Found file {0} -- deleting {1}" -f $newLogConfig, $log4netConfig)
Remove-Item $log4netConfig -Force
} else {
Write-Host ("$logLead : Could not find {0} -- renaming {1}" -f $newLogConfig, $log4netConfig)
Move-Item $log4netConfig $newLogConfig -Force
}
} else {
# Not a warning because we don't actually care
Write-Host ("No log4net.config found under {0}" -f $orbFolder)
}
}
}