< Summary - Kestrun — Combined Coverage

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

#LineLine coverage
 1<#
 2    .SYNOPSIS
 3        Adds environment information to the log context.
 4    .DESCRIPTION
 5        Adds environment information such as UserName and MachineName to the log context, allowing it to be included in 
 6    .PARAMETER LoggerConfig
 7        Instance of LoggerConfiguration
 8    .PARAMETER UserName
 9        If specified, enriches logs with the current user's name.
 10    .PARAMETER MachineName
 11        If specified, enriches logs with the current machine's name.
 12    .INPUTS
 13        None
 14    .OUTPUTS
 15        LoggerConfiguration object allowing method chaining
 16    .EXAMPLE
 17        PS> New-KrLogger | Add-KrEnrichEnvironment | Register-KrLogger
 18#>
 19function Add-KrEnrichEnvironment {
 20    [KestrunRuntimeApi('Everywhere')]
 21    [OutputType([Serilog.LoggerConfiguration])]
 22    [CmdletBinding()]
 23    param(
 24        [Parameter(Mandatory = $true, ValueFromPipeline = $true)]
 25        [Serilog.LoggerConfiguration]$loggerConfig,
 26        [Parameter(Mandatory = $false)]
 27        [switch]$UserName,
 28        [Parameter(Mandatory = $false)]
 29        [switch]$MachineName
 30    )
 31
 32    process {
 033        $hasEnricher = $false
 34
 35        # Only add if UserName is true or both are false (default: both on)
 036        if ($UserName -or (-not $UserName.IsPresent -and -not $MachineName.IsPresent)) {
 037            $loggerConfig = [Serilog.EnvironmentLoggerConfigurationExtensions]::WithEnvironmentUserName($loggerConfig.En
 038            $hasEnricher = $true
 39        }
 40        # Only add if MachineName is true or both are false (default: both on)
 041        if ($MachineName -or (-not $UserName.IsPresent -and -not $MachineName.IsPresent)) {
 042            $loggerConfig = [Serilog.EnvironmentLoggerConfigurationExtensions]::WithMachineName($loggerConfig.Enrich)
 043            $hasEnricher = $true
 44        }
 45
 046        if (-not $hasEnricher) {
 047            Write-Verbose 'No environment enrichers added.'
 48        }
 49
 050        return $loggerConfig
 51    }
 52}
 53

Methods/Properties

Add-KrEnrichEnvironment()