Public/ps1/Configuration/Logging/Set-ApprxrLogConfiguration.ps1
|
<#
.SYNOPSIS Sets the log configuration for Apprxr. .DESCRIPTION Stores log folder path, log retention hours, and log file retention count in the configuration. Uses defaults if values are not provided. .PARAMETER LogFolder The folder path (or file path) for log storage. If not provided, defaults to 'logfile.txt' in the configuration folder. .PARAMETER LogHours The number of hours to retain logs. Defaults to 24 if not specified. .PARAMETER LogRetention The number of log files to retain. Defaults to 7 if not specified. .EXAMPLE Set-ApprxrLogConfiguration -LogFolder 'C:\Logs' -LogHours 48 -LogRetention 10 Sets the log folder, retention hours, and file count. #> function Set-ApprxrLogConfiguration { param ( [String] $LogFolder, # Path to log folder or file [int] $LogHours, # Number of hours to retain logs [int] $LogRetention # Number of log files to retain ) # Set log folder path if ($LogFolder) { # Ensure the folder exists $logDir = Split-Path $LogFolder -Parent if ($logDir -and -not (Test-Path $logDir)) { New-Item -ItemType Directory -Path $logDir -Force | Out-Null } Set-ApprxrConfigurationValue -name LogFolder -value $LogFolder } else { $folder = Get-ApprxrConfigurationFolder if ($folder -and -not (Test-Path $folder)) { New-Item -ItemType Directory -Path $folder -Force | Out-Null } Set-ApprxrConfigurationValue -name LogFolder -value (Join-Path $folder "logfile.txt") } # Set log retention hours if ($LogHours) { Set-ApprxrConfigurationValue -name LogHours -value $LogHours } else { Set-ApprxrConfigurationValue -name LogHours -value 24 } # Set log file retention count if ($LogRetention) { Set-ApprxrConfigurationValue -name LogRetention -value $LogRetention } else { Set-ApprxrConfigurationValue -name LogRetention -value 7 } # Reload log configuration after changes Load-ApprxrLogConfiguration } |