< Summary - Kestrun — Combined Coverage

Information
Class: Public.Logging.sinks.Add-KrSinkSyslogTcp
Assembly: Kestrun.PowerShell.Public
File(s): /home/runner/work/Kestrun/Kestrun/src/PowerShell/Kestrun/Public/Logging/sinks/Add-KrSinkSyslogTcp.ps1
Tag: Kestrun/Kestrun@2d87023b37eb91155071c91dd3d6a2eeb3004705
Line coverage
0%
Covered lines: 0
Uncovered lines: 8
Coverable lines: 8
Total lines: 193
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 08/26/2025 - 01:25:22 Line coverage: 0% (0/2) Total lines: 102 Tag: Kestrun/Kestrun@07f821172e5dc3657f1be7e6818f18d6721cf38a09/04/2025 - 22:37:32 Line coverage: 0% (0/2) Total lines: 103 Tag: Kestrun/Kestrun@afb7aadc0a8a42bfa2b51ea62c8a6e2cf63faec609/06/2025 - 18:30:33 Line coverage: 0% (0/8) Total lines: 188 Tag: Kestrun/Kestrun@aeddbedb8a96e9137aac94c2d5edd011b57ac87110/13/2025 - 16:52:37 Line coverage: 0% (0/8) Total lines: 193 Tag: Kestrun/Kestrun@10d476bee71c71ad215bb8ab59f219887b5b4a5e

Metrics

File(s)

/home/runner/work/Kestrun/Kestrun/src/PowerShell/Kestrun/Public/Logging/sinks/Add-KrSinkSyslogTcp.ps1

#LineLine coverage
 1<#
 2.SYNOPSIS
 3    Adds a Syslog TCP sink to the logging system.
 4
 5.DESCRIPTION
 6    Configures a Serilog sink that sends log events to a Syslog server over TCP.
 7    Supports hostname, port, app name, framing, format, facility, TLS, certificate options,
 8    output template, minimum level, batching, severity mapping, and advanced syslog parameters.
 9
 10.PARAMETER LoggerConfig
 11    The Serilog LoggerConfiguration object to which the Syslog TCP sink will be added.
 12
 13.PARAMETER Hostname
 14    The hostname or IP address of the Syslog server to which log events will be sent.
 15
 16.PARAMETER Port
 17    The port number on which the Syslog server is listening. Defaults to 514.
 18
 19.PARAMETER AppName
 20    The application name to be included in the Syslog messages. If not specified, defaults to null.
 21
 22.PARAMETER FramingType
 23    The framing type to use for the Syslog messages. Defaults to OCTET_COUNTING.
 24
 25.PARAMETER Format
 26    The Syslog message format to use. Defaults to RFC5424.
 27
 28.PARAMETER Facility
 29    The Syslog facility to use for the log messages. Defaults to Local0.
 30
 31.PARAMETER UseTls
 32    Switch to enable TLS encryption for the TCP connection. Defaults to false.
 33
 34.PARAMETER CertProvider
 35    An optional certificate provider for secure connections.
 36
 37.PARAMETER CertValidationCallback
 38    An optional callback for validating server certificates.
 39
 40.PARAMETER OutputTemplate
 41    The output template string for formatting log messages.
 42
 43.PARAMETER RestrictedToMinimumLevel
 44    The minimum log event level required to write to the Syslog sink. Defaults to Verbose.
 45
 46.PARAMETER MessageIdPropertyName
 47    The property name used for RFC5424 message ID. Defaults to the sink’s built-in constant.
 48
 49.PARAMETER BatchSizeLimit
 50    Maximum number of events per batch (optional).
 51
 52.PARAMETER PeriodSeconds
 53    Flush period for batches in seconds (optional).
 54
 55.PARAMETER QueueLimit
 56    Maximum number of buffered events (optional).
 57
 58.PARAMETER EagerlyEmitFirstEvent
 59    If specified, the first event is sent immediately without waiting for the batch period.
 60
 61.PARAMETER SourceHost
 62    Optional value for the `sourceHost` field in syslog messages.
 63
 64.PARAMETER SeverityMapping
 65    Custom delegate to map Serilog log levels to syslog severities.
 66
 67.PARAMETER Formatter
 68    Optional custom ITextFormatter for full control over message formatting.
 69
 70.PARAMETER LevelSwitch
 71    Optional LoggingLevelSwitch to dynamically control the log level.
 72
 73.EXAMPLE
 74    # simplest: send logs over tcp with defaults
 75    Add-KrSinkSyslogTcp -LoggerConfig $config -Hostname "syslog.example.com"
 76
 77.EXAMPLE
 78    # custom port, app name, and TLS enabled
 79    Add-KrSinkSyslogTcp -LoggerConfig $config -Hostname "syslog.example.com" -Port 6514 -AppName "MyApp" -UseTls
 80
 81.EXAMPLE
 82    # use RFC3164 format and Local1 facility
 83    Add-KrSinkSyslogTcp -LoggerConfig $config -Hostname "syslog.example.com" -Format RFC3164 -Facility Local1
 84
 85.EXAMPLE
 86    # add batching configuration
 87    Add-KrSinkSyslogTcp -LoggerConfig $config -Hostname "syslog.example.com" `
 88        -BatchSizeLimit 50 -PeriodSeconds 1 -QueueLimit 5000 -EagerlyEmitFirstEvent
 89
 90.EXAMPLE
 91    # apply a custom severity mapping
 92    $map = [System.Func[Serilog.Events.LogEventLevel,Serilog.Sinks.Syslog.Severity]]{
 93        param($level)
 94        switch ($level) {
 95            'Information' { [Serilog.Sinks.Syslog.Severity]::Notice }
 96            'Fatal'       { [Serilog.Sinks.Syslog.Severity]::Emergency }
 97            default       { [Serilog.Sinks.Syslog.Severity]::Informational }
 98        }
 99    }
 100    Add-KrSinkSyslogTcp -LoggerConfig $config -Hostname "syslog.example.com" -SeverityMapping $map
 101
 102.EXAMPLE
 103    # advanced: secure connection with certificate validation
 104    $callback = [System.Net.Security.RemoteCertificateValidationCallback]{
 105        param($sender, $cert, $chain, $errors) $true
 106    }
 107    Add-KrSinkSyslogTcp -LoggerConfig $config -Hostname "syslog.example.com" -UseTls `
 108        -CertValidationCallback $callback -AppName "SecureApp"
 109
 110.NOTES
 111    This function is part of the Kestrun logging infrastructure and should be used to enable Syslog TCP logging.
 112#>
 113function Add-KrSinkSyslogTcp {
 114    [KestrunRuntimeApi('Everywhere')]
 115    [CmdletBinding()]
 116    [OutputType([Serilog.LoggerConfiguration])]
 117    param(
 118        [Parameter(Mandatory = $true, ValueFromPipeline = $true)]
 119        [Serilog.LoggerConfiguration]$LoggerConfig,
 120
 121        [Parameter(Mandatory = $true)]
 122        [string]$Hostname,
 123
 124        [int]$Port = 514,
 125        [string]$AppName = $null,
 126
 127        [Serilog.Sinks.Syslog.FramingType]$FramingType = [Serilog.Sinks.Syslog.FramingType]::OCTET_COUNTING,
 128        [Serilog.Sinks.Syslog.SyslogFormat]$Format = [Serilog.Sinks.Syslog.SyslogFormat]::RFC5424,
 129        [Serilog.Sinks.Syslog.Facility]$Facility = [Serilog.Sinks.Syslog.Facility]::Local0,
 130
 131        [switch]$UseTls,
 132
 133        [Serilog.Sinks.Syslog.ICertificateProvider]$CertProvider = $null,
 134        [System.Net.Security.RemoteCertificateValidationCallback]$CertValidationCallback = $null,
 135
 136        [string]$OutputTemplate,
 137        [Serilog.Events.LogEventLevel]$RestrictedToMinimumLevel = [Serilog.Events.LogEventLevel]::Verbose,
 138
 139        [string]$MessageIdPropertyName = [Serilog.Sinks.Syslog.Rfc5424Formatter]::DefaultMessageIdPropertyName,
 140
 141        [int]$BatchSizeLimit,
 142        [Parameter()]
 143        [ValidateRange(1, [int]::MaxValue)]
 144        [int]$PeriodSeconds,
 145        [Parameter()]
 146        [ValidateRange(1, [int]::MaxValue)]
 147        [int]$QueueLimit,
 148        [Parameter()]
 149        [switch]$EagerlyEmitFirstEvent,
 150
 151        [string]$SourceHost = $null,
 152        [System.Func``2[Serilog.Events.LogEventLevel, Serilog.Sinks.Syslog.Severity]]$SeverityMapping = $null,
 153        [Serilog.Formatting.ITextFormatter]$Formatter = $null,
 154        [Serilog.Core.LoggingLevelSwitch]$LevelSwitch = $null
 155    )
 156
 157    process {
 158        # Build PeriodicBatchingSinkOptions if batching args provided
 0159        $batchConfig = $null
 0160        if ($PSBoundParameters.ContainsKey('BatchSizeLimit') -or
 161            $PSBoundParameters.ContainsKey('PeriodSeconds') -or
 162            $PSBoundParameters.ContainsKey('QueueLimit') -or
 163            $EagerlyEmitFirstEvent.IsPresent) {
 164
 0165            $batchConfig = [Serilog.Sinks.PeriodicBatching.PeriodicBatchingSinkOptions]::new()
 0166            if ($PSBoundParameters.ContainsKey('BatchSizeLimit')) { $batchConfig.BatchSizeLimit = $BatchSizeLimit }
 0167            if ($PSBoundParameters.ContainsKey('PeriodSeconds')) { $batchConfig.Period = [TimeSpan]::FromSeconds($Period
 0168            if ($PSBoundParameters.ContainsKey('QueueLimit')) { $batchConfig.QueueLimit = $QueueLimit }
 0169            if ($EagerlyEmitFirstEvent.IsPresent) { $batchConfig.EagerlyEmitFirstEvent = $true }
 170        }
 171
 0172        return [Serilog.SyslogLoggerConfigurationExtensions]::TcpSyslog(
 173            $LoggerConfig.WriteTo,     # 1 loggerSinkConfig
 174            $Hostname,                 # 2 host
 175            $Port,                     # 3 port
 176            $AppName,                  # 4 appName
 177            $FramingType,              # 5 framingType
 178            $Format,                   # 6 format
 179            $Facility,                 # 7 facility
 180            $UseTls.IsPresent,         # 8 useTls (bool)
 181            $CertProvider,             # 9 certProvider
 182            $CertValidationCallback,   # 10 certValidationCallback
 183            $OutputTemplate,           # 11 outputTemplate
 184            $RestrictedToMinimumLevel, # 12 restrictedToMinimumLevel
 185            $MessageIdPropertyName,    # 13 messageIdPropertyName
 186            $batchConfig,              # 14 batchConfig
 187            $SourceHost,               # 15 sourceHost
 188            $SeverityMapping,          # 16 severityMapping
 189            $Formatter,                # 17 formatter
 190            $LevelSwitch               # 18 levelSwitch
 191        )
 192    }
 193}

Methods/Properties

Add-KrSinkSyslogTcp()