< Summary - Kestrun — Combined Coverage

Information
Class: Public.Logging.sinks.Add-KrSinkConsole
Assembly: Kestrun.PowerShell.Public
File(s): /home/runner/work/Kestrun/Kestrun/src/PowerShell/Kestrun/Public/Logging/sinks/Add-KrSinkConsole.ps1
Tag: Kestrun/Kestrun@9d3a582b2d63930269564a7591aa77ef297cadeb
Line coverage
0%
Covered lines: 0
Uncovered lines: 3
Coverable lines: 3
Total lines: 84
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/Public/Logging/sinks/Add-KrSinkConsole.ps1

#LineLine coverage
 1<#
 2    .SYNOPSIS
 3        Adds a console logging sink to the Kestrun logging system.
 4    .DESCRIPTION
 5        The Add-KrSinkConsole function configures and adds a console output sink for logging messages within the Kestrun
 6    .PARAMETER LoggerConfig
 7        The Serilog LoggerConfiguration object to which the console sink will be added.
 8    .PARAMETER RestrictedToMinimumLevel
 9        The minimum log event level required to write to the console sink. Defaults to Verbose.
 10    .PARAMETER OutputTemplate
 11        The output template string for formatting log messages. Defaults to '[{Timestamp:HH:mm:ss} {Level:u3}] {Message:
 12    .PARAMETER FormatProvider
 13        An optional format provider for customizing message formatting.
 14    .PARAMETER LevelSwitch
 15        An optional LoggingLevelSwitch to dynamically control the logging level.
 16    .PARAMETER StandardErrorFromLevel
 17        An optional log event level at which messages are written to standard error.
 18    .PARAMETER Theme
 19        An optional console theme for customizing log output appearance.
 20    .PARAMETER Formatter
 21        An optional text formatter for custom log message formatting (used in 'Formatter' parameter set).
 22    .EXAMPLE
 23        Add-KrSinkConsole -LoggerConfig $config
 24        Adds a console sink to the logging system, allowing log messages to be output to the console.
 25    .EXAMPLE
 26        Add-KrSinkConsole -LoggerConfig $config -RestrictedToMinimumLevel Information
 27        Adds a console sink that only outputs log events at Information level or higher.
 28    .EXAMPLE
 29        Add-KrSinkConsole -LoggerConfig $config -OutputTemplate '[{Level}] {Message}{NewLine}'
 30        Customizes the output template for console log messages.
 31    .EXAMPLE
 32        Add-KrSinkConsole -LoggerConfig $config -Formatter $customFormatter
 33        Uses a custom text formatter for console log output.
 34    .NOTES
 35        This function is part of the Kestrun logging infrastructure and should be used to enable console logging.
 36#>
 37function Add-KrSinkConsole {
 38    [KestrunRuntimeApi('Everywhere')]
 39    [CmdletBinding(DefaultParameterSetName = 'Default')]
 40    [OutputType([Serilog.LoggerConfiguration])]
 41    param(
 42        [Parameter(Mandatory = $true, ValueFromPipeline = $true)]
 43        [Serilog.LoggerConfiguration]$LoggerConfig,
 44        [Parameter(Mandatory = $false)]
 45        [Serilog.Events.LogEventLevel]$RestrictedToMinimumLevel = [Serilog.Events.LogEventLevel]::Verbose,
 46        [Parameter(Mandatory = $false)]
 47        [string]$OutputTemplate = '[{Timestamp:HH:mm:ss} {Level:u3}] {Message:lj}{NewLine}{ErrorRecord}{Exception}',
 48        [Parameter(Mandatory = $false)]
 49        [System.IFormatProvider]$FormatProvider = $null,
 50        [Parameter(Mandatory = $false)]
 51        [Serilog.Core.LoggingLevelSwitch]$LevelSwitch = $null,
 52        [Parameter(Mandatory = $false)]
 53        [Nullable[Serilog.Events.LogEventLevel]]$StandardErrorFromLevel = $null,
 54        [Parameter(Mandatory = $false)]
 55        [Serilog.Sinks.SystemConsole.Themes.ConsoleTheme]$Theme,
 56        [Parameter(Mandatory = $false, ParameterSetName = 'Formatter')]
 57        [Serilog.Formatting.ITextFormatter]$Formatter
 58
 59    )
 60
 61    process {
 062        switch ($PSCmdlet.ParameterSetName) {
 63            'Default' {
 064                return [Serilog.ConsoleLoggerConfigurationExtensions]::Console($LoggerConfig.WriteTo,
 65                    $RestrictedToMinimumLevel,
 66                    $OutputTemplate,
 67                    $FormatProvider,
 68                    $LevelSwitch,
 69                    $StandardErrorFromLevel,
 70                    $Theme
 71                )
 72            }
 73            'Formatter' {
 074                return [Serilog.ConsoleLoggerConfigurationExtensions]::Console($LoggerConfig.WriteTo,
 75                    $Formatter,
 76                    $RestrictedToMinimumLevel,
 77                    $LevelSwitch,
 78                    $StandardErrorFromLevel
 79                )
 80            }
 81        }
 82    }
 83}
 84

Methods/Properties

Add-KrSinkConsole()