| | | 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 | | #> |
| | | 14 | | function Set-KrLogLevelToPreference { |
| | | 15 | | [CmdletBinding(SupportsShouldProcess = $true)] |
| | | 16 | | param( |
| | | 17 | | [Parameter(Mandatory = $true)] |
| | | 18 | | [Serilog.Events.LogEventLevel]$Level |
| | | 19 | | ) |
| | | 20 | | |
| | 0 | 21 | | if ($PSCmdlet.ShouldProcess('Set log level preferences')) { |
| | 0 | 22 | | if ([int]$Level -le [int]([Serilog.Events.LogEventLevel]::Verbose)) { |
| | 0 | 23 | | Set-Variable VerbosePreference -Value 'Continue' -Scope Global |
| | | 24 | | } else { |
| | 0 | 25 | | Set-Variable VerbosePreference -Value 'SilentlyContinue' -Scope Global |
| | | 26 | | } |
| | | 27 | | |
| | 0 | 28 | | if ([int]$Level -le [int]([Serilog.Events.LogEventLevel]::Debug)) { |
| | 0 | 29 | | Set-Variable DebugPreference -Value 'Continue' -Scope Global |
| | | 30 | | } else { |
| | 0 | 31 | | Set-Variable DebugPreference -Value 'SilentlyContinue' -Scope Global |
| | | 32 | | } |
| | | 33 | | |
| | 0 | 34 | | if ([int]$Level -le [int]([Serilog.Events.LogEventLevel]::Information)) { |
| | 0 | 35 | | Set-Variable InformationPreference -Value 'Continue' -Scope Global |
| | | 36 | | } else { |
| | 0 | 37 | | Set-Variable InformationPreference -Value 'SilentlyContinue' -Scope Global |
| | | 38 | | } |
| | | 39 | | |
| | 0 | 40 | | if ([int]$Level -le [int]([Serilog.Events.LogEventLevel]::Warning)) { |
| | 0 | 41 | | Set-Variable WarningPreference -Value 'Continue' -Scope Global |
| | | 42 | | } else { |
| | 0 | 43 | | Set-Variable WarningPreference -Value 'SilentlyContinue' -Scope Global |
| | | 44 | | } |
| | | 45 | | } |
| | | 46 | | } |
| | | 47 | | |