| | | 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-KrLoggerLevel -LoggerConfig $myLoggerConfig -Values Warning |
| | | 19 | | Sets the minimum log level of the specified logger configuration to Warning. |
| | | 20 | | .EXAMPLE |
| | | 21 | | PS> Set-KrLoggerLevel -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-KrLoggerLevel -Value Information -PassThru |
| | | 25 | | Sets the minimum log level of the specified logger configuration to Information and outputs the LoggerConfigurat |
| | | 26 | | #> |
| | | 27 | | function Set-KrLoggerLevel { |
| | | 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 | | [Alias('Level')] |
| | | 37 | | [Serilog.Events.LogEventLevel]$Value, |
| | | 38 | | [Parameter(Mandatory = $true, ParameterSetName = 'Dynamic')] |
| | | 39 | | [Serilog.Events.LogEventLevel]$Dynamic |
| | | 40 | | ) |
| | | 41 | | |
| | | 42 | | process { |
| | 0 | 43 | | if ($PsCmdlet.ParameterSetName -eq 'Dynamic') { |
| | 0 | 44 | | return [Kestrun.Logging.LoggerConfigurationExtensions]::EnsureSwitch($LoggerConfig, $Dynamic) |
| | | 45 | | } else { |
| | 0 | 46 | | switch ($Value) { |
| | 0 | 47 | | Verbose { return $LoggerConfig.MinimumLevel.Verbose() } |
| | 0 | 48 | | Debug { return $LoggerConfig.MinimumLevel.Debug() } |
| | 0 | 49 | | Information { return $LoggerConfig.MinimumLevel.Information() } |
| | 0 | 50 | | Warning { return $LoggerConfig.MinimumLevel.Warning() } |
| | 0 | 51 | | Error { return $LoggerConfig.MinimumLevel.Error() } |
| | 0 | 52 | | Fatal { return $LoggerConfig.MinimumLevel.Fatal() } |
| | 0 | 53 | | default { return $LoggerConfig.MinimumLevel.Information() } |
| | | 54 | | } |
| | | 55 | | } |
| | | 56 | | } |
| | | 57 | | } |
| | | 58 | | |