| | 1 | | <# |
| | 2 | | .SYNOPSIS |
| | 3 | | Gets the current logging level for a level switch. |
| | 4 | | .DESCRIPTION |
| | 5 | | Retrieves the current logging level for a specified level switch. If the LoggerName is not provided, |
| | 6 | | it will be derived from the provided Logger instance. |
| | 7 | | .PARAMETER Logger |
| | 8 | | An instance of Serilog.Core.Logger to set the level switch for. |
| | 9 | | It's mutually exclusive with the LoggerName parameter. |
| | 10 | | .PARAMETER LoggerName |
| | 11 | | The name of a registered logger to set the level switch for. |
| | 12 | | It's mutually exclusive with the Logger parameter. |
| | 13 | | .EXAMPLE |
| | 14 | | PS> Get-KrLevelSwitch -LoggerName "MyLogger" |
| | 15 | | Retrieves the current logging level of the level switch for the logger named "MyLogger". |
| | 16 | | .EXAMPLE |
| | 17 | | PS> Get-KrLevelSwitch -Logger $myLogger |
| | 18 | | Retrieves the current logging level of the level switch for the specified logger instance. |
| | 19 | | #> |
| | 20 | | function Get-KrLevelSwitch { |
| | 21 | | [KestrunRuntimeApi('Everywhere')] |
| | 22 | | [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseShouldProcessForStateChangingFunctions', '')] |
| | 23 | | [CmdletBinding(DefaultParameterSetName = 'LoggerName')] |
| | 24 | | [OutputType([Serilog.Events.LogEventLevel])] |
| | 25 | | param( |
| | 26 | | [Parameter(Mandatory = $false, ParameterSetName = 'LoggerName')] |
| | 27 | | [string]$LoggerName, |
| | 28 | | [Parameter(Mandatory = $true, ParameterSetName = 'Logger')] |
| | 29 | | [Serilog.Core.Logger]$Logger |
| | 30 | | ) |
| | 31 | |
|
| 0 | 32 | | if ([string]::IsNullOrEmpty($LoggerName)) { |
| 0 | 33 | | $LoggerName = [Kestrun.Logging.LoggerManager]::GetName($Logger) |
| | 34 | | } |
| 0 | 35 | | if ([string]::IsNullOrEmpty($LoggerName)) { |
| 0 | 36 | | throw [System.ArgumentException]::new("LoggerName cannot be null or empty.") |
| | 37 | | } |
| | 38 | |
|
| 0 | 39 | | $levelSwitch = [Kestrun.Logging.LoggerManager]::GetLevelSwitch($LoggerName) |
| 0 | 40 | | if ($null -eq $levelSwitch) { |
| 0 | 41 | | throw [System.InvalidOperationException]::new("Level switch not found for logger '$LoggerName'. Ensure that the |
| | 42 | | } |
| 0 | 43 | | return $levelSwitch.MinimumLevel |
| | 44 | | } |
| | 45 | |
|