< Summary - Kestrun — Combined Coverage

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

#LineLine coverage
 1<#
 2    .SYNOPSIS
 3        Closes the logger and flushes all logs.
 4    .DESCRIPTION
 5        Closes the logger and flushes all logs. If no logger is specified, it will close the default logger.
 6    .PARAMETER Logger
 7        Instance of Serilog.Logger to close. If not specified, the default logger will be closed.
 8    .PARAMETER LoggerName
 9        Name of the logger to close. If specified, the logger with this name will be closed
 10    .PARAMETER DefaultLogger
 11        If specified, closes the default logger.
 12    .INPUTS
 13        Instance of Serilog.Logger
 14    .OUTPUTS
 15        None. This cmdlet does not return any output.
 16    .EXAMPLE
 17        PS> Close-KrLogger -Logger $myLogger
 18        Closes the specified logger and flushes all logs.
 19    .EXAMPLE
 20        PS> Close-KrLogger
 21        Closes all active loggers and flushes any remaining logs.
 22    .EXAMPLE
 23        PS> Close-KrLogger -LoggerName 'MyLogger'
 24        Closes the logger with the specified name and any remaining logs.
 25    .EXAMPLE
 26        PS> Close-KrLogger -DefaultLogger
 27        Closes the default logger and flushes any remaining logs.
 28#>
 29function Close-KrLogger {
 30    [KestrunRuntimeApi('Everywhere')]
 31    [CmdletBinding(DefaultParameterSetName = 'AllLogs')]
 32    param(
 33        [Parameter(Mandatory = $false, ValueFromPipeline = $true, ParameterSetName = 'Logger')]
 34        [Serilog.ILogger]$Logger,
 35
 36        [Parameter(Mandatory = $false, ParameterSetName = 'LoggerName')]
 37        [string]$LoggerName,
 38
 39        [Parameter(Mandatory = $false, ParameterSetName = 'Default')]
 40        [switch]$DefaultLogger
 41    )
 42
 43    process {
 044        if ($DefaultLogger) {
 045            $Logger = [Kestrun.Logging.LoggerManager]::GetDefault()
 046        } elseif ($Null -eq $Logger) {
 047            if (-not [string]::IsNullOrEmpty($LoggerName)) {
 48                # If LoggerName is specified, get the logger with that name
 049                $Logger = [Kestrun.Logging.LoggerManager]::Get($LoggerName)
 50            }
 51        }
 052        if ($null -ne $Logger) {
 53            # Close the specified logger
 054            $null = [Kestrun.Logging.LoggerManager]::CloseAndFlush($Logger)
 55        } else {
 56            # Close all loggers
 057            [Kestrun.Logging.LoggerManager]::Clear()
 58        }
 59    }
 60}
 61

Methods/Properties

Close-KrLogger()