< Summary - Kestrun — Combined Coverage

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

#LineLine coverage
 1<#
 2    .SYNOPSIS
 3        Push a property into Serilog's LogContext for the current scope.
 4    .DESCRIPTION
 5        Adds a property to Serilog's ambient LogContext so all log events written within the scope
 6        include the property. Returns an IDisposable; dispose it to remove the property.
 7
 8        Requires the logger to be configured with Add-KrEnrichFromLogContext.
 9    .PARAMETER Name
 10        Property name to attach.
 11    .PARAMETER Value
 12        Property value to attach.
 13    .PARAMETER Destructure
 14        If set, complex objects will be destructured into structured properties.
 15    .OUTPUTS
 16        System.IDisposable
 17    .EXAMPLE
 18        PS> $d = Push-KrLogContextProperty -Name CorrelationId -Value $corr
 19        PS> try { Write-KrLog -Level Information -Message 'Hello' } finally { $d.Dispose() }
 20#>
 21function Push-KrLogContextProperty {
 22    [KestrunRuntimeApi('Everywhere')]
 23    [CmdletBinding()]
 24    [OutputType([System.IDisposable])]
 25    param(
 26        [Parameter(Mandatory = $true)]
 27        [string]$Name,
 28        [Parameter(Mandatory = $true)]
 29        [object]$Value,
 30        [Parameter(Mandatory = $false)]
 31        [switch]$Destructure
 32    )
 33
 34    process {
 035        if ($Destructure) {
 036            return [Serilog.Context.LogContext]::PushProperty($Name, $Value, $true)
 37        }
 038        return [Serilog.Context.LogContext]::PushProperty($Name, $Value)
 39    }
 40}

Methods/Properties

Push-KrLogContextProperty()