Public/Set-P1LogLevel.ps1

function Set-P1LogLevel {
    <#
    .Synopsis
    Set the log level of PlannerOne
 
    .Description
    Set the log level of PlannerOne service and PlannerOne Web.
    Standard level are Info and Debug.
    PlannerOne Web and Service must be restarted to take the new option into account.
    PlannerOne Web and Service will be restarted if option -Restart is set.
    Configuration is persisted and reapplied after a switch version.
    Use -NoPersist to change only the current installed version.
    The default value is Info.
    The following levels are defined in order of increasing priority:
    - ALL
    - DEBUG
    - INFO
    - WARN
    - ERROR
    - FATAL
    - OFF
    Current log level can be obtain with Get-P1LogLevel.
 
    .Parameter Tenant
    The target tenant.
 
    .Parameter Level
    The log level to set.
 
    .Parameter Restart
    Restart the PlannerOne Web Application and the PlannerOne Service after the new log level has been set.
 
    .Parameter NoPersist
    Do not persist the configuration for next upgrade.
 
    .Example
    # Set the tenant PROD to Debug and restart
    Set-P1LogLevel -Tenant PROD -Level DEBUG -Restart
#>

    [cmdletbinding()]
    param(
        [Parameter(Mandatory=$true)]
        [string] $Tenant,
        [Parameter(Mandatory=$true)]
        [string] $Level,
        [switch] $Restart,
        [switch] $NoPersist
    )
    Process
    {
        Write-Section "Setting log level to $Level for tenant $Tenant"
        if (!(Test-Tenant $Tenant)) {
            Write-Warning "Tenant $Tenant does not exist."
            Write-Warning "Operation canceled."
            return;
        }

        $levelOK = Test-LogLevel $Level
        if (!$levelOK) {
            Write-Warning "Log level is not correct."
            Write-LogLevels
            Write-Warning "Operation canceled."
            return
        }

        $info = Get-P1Tenant $Tenant
        $webApp = Get-P1WebApplication $Tenant
        if ($webApp -eq $null) {
                Write-KO "Cannot find the web application for tenant $Tenant"
                return
        }

        $webPath = $webApp.PhysicalPath
        Write-Verbose "Web physical path is $webPath"
        Write-Log4NetWeb $webPath $Level
        $servicePath = $info.Path
        Write-Verbose "Service physical path is $servicePath"
        Write-Log4NetService $servicePath $Level

        if (!$NoPersist) {
            Write-LogLevel $Tenant $Level
        }

        if ($Restart) {
            Restart-Tenant $webApp $info
        }

        Write-OK "Log level set to $Level for tenant $Tenant"
    }
}