Private/LogUtil.ps1
$LogLevels = ("ALL", "DEBUG", "INFO", "WARN", "ERROR", "FATAL", "OFF") $logConfDir = "Logs\" $logConfFile = "loglevel" $log4NetFile = "Log4Net.config" function Test-LogLevel([string] $Level) { [bool]$found = $false foreach($logLevel in $LogLevels) { if ($Level -eq $logLevel) { $found = $true break } } return $found } function Write-LogLevels() { Write-Output "Available levels:" Write-Output $LogLevels } function Get-LogConfigDirFromTenant([string]$Tenant) { $configPath = Get-ConfigPathFromTenant $Tenant $logConfPath = $configPath + $logConfDir return $logConfPath } function Get-LogConfigPathFromTenant([string]$Tenant) { $configDir = Get-LogConfigDirFromTenant $Tenant $logConfPath = $configDir + $logConfFile Write-Verbose "Log configuration path is $logConfPath" return $logConfPath } function Read-LogLevel([string]$Tenant) { $path = Get-LogConfigPathFromTenant $Tenant if (!(Test-Path $path)) { Write-Verbose "File $path does not exist. Returning default log level" return "INFO" } $level = Get-Content $path return $level } function Write-LogLevel([string]$Tenant, [string]$Level) { $path = Get-LogConfigPathFromTenant $Tenant $dir = Get-LogConfigDirFromTenant $Tenant if (!(Test-Path $dir)) { Write-Verbose "Creating dir $dir" mkdir $dir | Out-Null } $path = Get-LogConfigPathFromTenant $Tenant Write-Verbose "Writing $Level to $path" Set-Content $path $Level } function Get-Log4NetPath($dirPath) { $path = $dirPath + "\" + $log4NetFile return $path } function Write-Log4NetWeb([string]$dirPath, [string]$Level) { $path = Get-Log4NetPath $dirPath Write-Verbose "Reading $path" [xml]$config = Get-Content $path Write-Verbose "Setting root level to $Level" $config.configuration.log4net.root.level.value = "$Level" Write-Verbose "Saving Log4Net xml configuration" $config.save($path) } function Write-Log4NetService([string]$dirPath, [string]$Level) { $confServiceDirPath = $dirPath + "\Conf\Service" $path = Get-Log4NetPath $confServiceDirPath Write-Verbose "Reading $path" [xml]$config = Get-Content $path Write-Verbose "Setting root level to $Level" $config.configuration.log4net.appender[0].threshold.value = "$Level" Write-Verbose "Saving Log4Net xml configuration" $config.save($path) } |