< Summary - Kestrun — Combined Coverage

Information
Class: Private.Logging.Set-KrLogLevelToPreference
Assembly: Kestrun.PowerShell.Private
File(s): /home/runner/work/Kestrun/Kestrun/src/PowerShell/Kestrun/Private/Logging/Set-KrLogLevelToPreference.ps1
Tag: Kestrun/Kestrun@9d3a582b2d63930269564a7591aa77ef297cadeb
Line coverage
0%
Covered lines: 0
Uncovered lines: 13
Coverable lines: 13
Total lines: 47
Line coverage: 0%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Coverage history

Coverage history 0 25 50 75 100

Metrics

File(s)

/home/runner/work/Kestrun/Kestrun/src/PowerShell/Kestrun/Private/Logging/Set-KrLogLevelToPreference.ps1

#LineLine coverage
 1<#
 2    .SYNOPSIS
 3        Sets the PowerShell script log level preferences based on the specified Serilog log level.
 4    .DESCRIPTION
 5        This function adjusts the PowerShell script log level preferences (Verbose, Debug, Information, Warning)
 6        based on the provided Serilog log level.
 7    .PARAMETER Level
 8        The Serilog log level to set as the preference.
 9        Pass the Serilog log level that will be used to set the PowerShell script log level preferences.
 10    .EXAMPLE
 11        Set-KrLogLevelToPreference -Level 'Error'
 12        # This will set the PowerShell script log level preferences to 'SilentlyContinue' for all levels above Error.
 13#>
 14function Set-KrLogLevelToPreference {
 15    [CmdletBinding(SupportsShouldProcess = $true)]
 16    param(
 17        [Parameter(Mandatory = $true)]
 18        [Serilog.Events.LogEventLevel]$Level
 19    )
 20
 021    if ($PSCmdlet.ShouldProcess('Set log level preferences')) {
 022        if ([int]$Level -le [int]([Serilog.Events.LogEventLevel]::Verbose)) {
 023            Set-Variable VerbosePreference -Value 'Continue' -Scope Global
 24        } else {
 025            Set-Variable VerbosePreference -Value 'SilentlyContinue' -Scope Global
 26        }
 27
 028        if ([int]$Level -le [int]([Serilog.Events.LogEventLevel]::Debug)) {
 029            Set-Variable DebugPreference -Value 'Continue' -Scope Global
 30        } else {
 031            Set-Variable DebugPreference -Value 'SilentlyContinue' -Scope Global
 32        }
 33
 034        if ([int]$Level -le [int]([Serilog.Events.LogEventLevel]::Information)) {
 035            Set-Variable InformationPreference -Value 'Continue' -Scope Global
 36        } else {
 037            Set-Variable InformationPreference -Value 'SilentlyContinue' -Scope Global
 38        }
 39
 040        if ([int]$Level -le [int]([Serilog.Events.LogEventLevel]::Warning)) {
 041            Set-Variable WarningPreference -Value 'Continue' -Scope Global
 42        } else {
 043            Set-Variable WarningPreference -Value 'SilentlyContinue' -Scope Global
 44        }
 45    }
 46}
 47

Methods/Properties

Set-KrLogLevelToPreference()