< Summary - Kestrun — Combined Coverage

Information
Class: Private.Logging.Get-KrFormattedMessage
Assembly: Kestrun.PowerShell.Private
File(s): /home/runner/work/Kestrun/Kestrun/src/PowerShell/Kestrun/Private/Logging/Get-KrFormattedMessage.ps1
Tag: Kestrun/Kestrun@9d3a582b2d63930269564a7591aa77ef297cadeb
Line coverage
0%
Covered lines: 0
Uncovered lines: 9
Coverable lines: 9
Total lines: 60
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/Private/Logging/Get-KrFormattedMessage.ps1

#LineLine coverage
 1<#
 2    .SYNOPSIS
 3        Formats a log message for the specified logger and log level.
 4    .DESCRIPTION
 5        This function takes a log message and its parameters, and formats it for the specified logger and log level.
 6    .PARAMETER Logger
 7        The Serilog logger instance to use for formatting the message.
 8        Pass the logger instance that will be used to format the log message.
 9    .PARAMETER Level
 10        The log level to use for the log message.
 11        Pass the log level that will be used to format the log message.
 12    .PARAMETER Message
 13        The log message to format.
 14        Pass the log message that will be formatted for the specified logger and log level.
 15    .PARAMETER Values
 16        An array of values to use for formatting the log message.
 17        Pass the values that will be used to format the log message.
 18    .PARAMETER Exception
 19        The exception to include in the log message, if any.
 20        Pass the exception that will be included in the log message.
 21    .EXAMPLE
 22        $formattedMessage = Get-KrFormattedMessage -Logger $logger -Level 'Error' -Message 'An error occurred: {ErrorMes
 23        $formattedMessage | Write-Host
 24        # Output the formatted message
 25        Write-Host $formattedMessage
 26#>
 27function Get-KrFormattedMessage {
 28    param(
 29        [Parameter(Mandatory = $true)]
 30        [Serilog.ILogger]$Logger,
 31
 32        [Parameter(Mandatory = $true)]
 33        [Serilog.Events.LogEventLevel]$Level,
 34
 35        [parameter(Mandatory = $true)]
 36        [AllowEmptyString()]
 37        [string]$Message,
 38
 39        [Parameter(Mandatory = $false)]
 40        [AllowNull()]
 41        [object[]]$Values,
 42
 43        [Parameter(Mandatory = $false)]
 44        [AllowNull()]
 45        [System.Exception]$Exception
 46    )
 47
 048    $parsedTemplate = $null
 049    $boundProperties = $null
 050    if ($Logger.BindMessage($Message, $Values, [ref]$parsedTemplate, [ref]$boundProperties)) {
 051        $logEvent = [Serilog.Events.LogEvent]::new([System.DateTimeOffset]::Now, $Level, $Exception, $parsedTemplate, $b
 052        $strWriter = [System.IO.StringWriter]::new()
 53        # Use the global TextFormatter if available, otherwise use the default formatter from Kestrun.Logging
 054        [Kestrun.Logging]::TextFormatter.Format($logEvent, $strWriter)
 055        $message = $strWriter.ToString()
 056        $strWriter.Dispose()
 057        $message
 58    }
 59}
 60

Methods/Properties

Get-KrFormattedMessage()