| | 1 | | <# |
| | 2 | | .SYNOPSIS |
| | 3 | | Sets the minimum log level for the logger configuration. |
| | 4 | | .DESCRIPTION |
| | 5 | | Sets the minimum log level for the logger configuration. This cmdlet can be used to |
| | 6 | | set the minimum log level to a specific level or to the user's preference. |
| | 7 | | .PARAMETER LoggerConfig |
| | 8 | | Instance of Serilog.LoggerConfiguration to set the minimum level for. |
| | 9 | | .PARAMETER Value |
| | 10 | | The minimum log level to set for the logger configuration. |
| | 11 | | .PARAMETER Dynamic |
| | 12 | | If specified, the minimum log level will be controlled by a level switch. |
| | 13 | | .INPUTS |
| | 14 | | Instance of Serilog.LoggerConfiguration |
| | 15 | | .OUTPUTS |
| | 16 | | Instance of Serilog.LoggerConfiguration if the PassThru parameter is specified. |
| | 17 | | .EXAMPLE |
| | 18 | | PS> Set-KrMinimumLevel -LoggerConfig $myLoggerConfig -Value Warning |
| | 19 | | Sets the minimum log level of the specified logger configuration to Warning. |
| | 20 | | .EXAMPLE |
| | 21 | | PS> Set-KrMinimumLevel -LoggerConfig $myLoggerConfig -ControlledBy $myLevelSwitch |
| | 22 | | Sets the minimum log level of the specified logger configuration to be controlled by the specified level switch. |
| | 23 | | .EXAMPLE |
| | 24 | | PS> $myLoggerConfig | Set-KrMinimumLevel -Value Information -PassThru |
| | 25 | | Sets the minimum log level of the specified logger configuration to Information and outputs the LoggerConfigurat |
| | 26 | | #> |
| | 27 | | function Set-KrMinimumLevel { |
| | 28 | | [KestrunRuntimeApi('Everywhere')] |
| | 29 | | [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseShouldProcessForStateChangingFunctions', '')] |
| | 30 | | [OutputType([Serilog.LoggerConfiguration])] |
| | 31 | | [CmdletBinding(DefaultParameterSetName = 'Static')] |
| | 32 | | param( |
| | 33 | | [Parameter(Mandatory = $true, ValueFromPipeline = $true)] |
| | 34 | | [Serilog.LoggerConfiguration]$LoggerConfig, |
| | 35 | | [Parameter(Mandatory = $true, ParameterSetName = 'Static')] |
| | 36 | | [Serilog.Events.LogEventLevel]$Value, |
| | 37 | | [Parameter(Mandatory = $true, ParameterSetName = 'Dynamic')] |
| | 38 | | [Serilog.Events.LogEventLevel]$Dynamic |
| | 39 | | ) |
| | 40 | |
|
| | 41 | | process { |
| 1 | 42 | | if ($PsCmdlet.ParameterSetName -eq 'Dynamic') { |
| 0 | 43 | | return [Kestrun.Logging.LoggerConfigurationExtensions]::EnsureSwitch($LoggerConfig, $Dynamic) |
| | 44 | | } else { |
| 1 | 45 | | switch ($Value) { |
| 0 | 46 | | Verbose { return $LoggerConfig.MinimumLevel.Verbose() } |
| 1 | 47 | | Debug { return $LoggerConfig.MinimumLevel.Debug() } |
| 0 | 48 | | Information { return $LoggerConfig.MinimumLevel.Information() } |
| 0 | 49 | | Warning { return $LoggerConfig.MinimumLevel.Warning() } |
| 0 | 50 | | Error { return $LoggerConfig.MinimumLevel.Error() } |
| 0 | 51 | | Fatal { return $LoggerConfig.MinimumLevel.Fatal() } |
| 0 | 52 | | default { return $LoggerConfig.MinimumLevel.Information() } |
| | 53 | | } |
| | 54 | | } |
| | 55 | | } |
| | 56 | | } |
| | 57 | |
|