| | 1 | | <# |
| | 2 | | .SYNOPSIS |
| | 3 | | Adds a Syslog Local sink to the Serilog logger configuration. |
| | 4 | | .DESCRIPTION |
| | 5 | | The Add-KrSinkSyslogLocal function configures a logging sink that sends log events to the local Syslog server. |
| | 6 | | It allows customization of the application name, Syslog facility, output template, and minimum log level. |
| | 7 | | .PARAMETER LoggerConfig |
| | 8 | | The Serilog LoggerConfiguration object to which the Syslog Local sink will be added. |
| | 9 | | .PARAMETER AppName |
| | 10 | | The application name to be included in the Syslog messages. If not specified, defaults to null. |
| | 11 | | .PARAMETER Facility |
| | 12 | | The Syslog facility to use for the log messages. Defaults to Local0. |
| | 13 | | .PARAMETER OutputTemplate |
| | 14 | | The output template string for formatting log messages. Defaults to '{Message}{NewLine}{Exception}{ErrorRecord}' |
| | 15 | | .PARAMETER RestrictedToMinimumLevel |
| | 16 | | The minimum log event level required to write to the Syslog sink. Defaults to Verbose. |
| | 17 | | .PARAMETER SeverityMapping |
| | 18 | | An optional function to map Serilog log levels to Syslog severity levels. |
| | 19 | | .PARAMETER Formatter |
| | 20 | | An optional ITextFormatter for custom message formatting. |
| | 21 | | .PARAMETER LevelSwitch |
| | 22 | | An optional LoggingLevelSwitch to dynamically control the minimum log level. |
| | 23 | | .EXAMPLE |
| | 24 | | Add-KrSinkSyslogLocal -LoggerConfig $config -AppName "MyApp" -Facility Local1 -OutputTemplate "{Message}{NewLine |
| | 25 | | Adds a Syslog Local sink to the logging system that sends log events with the specified application name, facili |
| | 26 | | .EXAMPLE |
| | 27 | | Add-KrSinkSyslogLocal -LoggerConfig $config |
| | 28 | | Adds a Syslog Local sink to the logging system with default parameters. |
| | 29 | | .EXAMPLE |
| | 30 | | Add-KrSinkSyslogLocal -LoggerConfig $config -AppName "MyApp" -SeverityMapping { param($level) if ($level -eq 'Er |
| | 31 | | Adds a Syslog Local sink with a custom severity mapping function. |
| | 32 | | .EXAMPLE |
| | 33 | | Add-KrSinkSyslogLocal -LoggerConfig $config -LevelSwitch $levelSwitch |
| | 34 | | Adds a Syslog Local sink with a dynamic level switch to control the minimum log level. |
| | 35 | | .NOTES |
| | 36 | | This function is part of the Kestrun logging infrastructure and should be used to enable Syslog Local logging. |
| | 37 | | #> |
| | 38 | | function Add-KrSinkSyslogLocal { |
| | 39 | | [KestrunRuntimeApi('Everywhere')] |
| | 40 | | [CmdletBinding()] |
| | 41 | | [OutputType([Serilog.LoggerConfiguration])] |
| | 42 | | param( |
| | 43 | | [Parameter(Mandatory = $true, ValueFromPipeline = $true)] |
| | 44 | | [Serilog.LoggerConfiguration]$LoggerConfig, |
| | 45 | |
|
| | 46 | | [Parameter(Mandatory = $false)] |
| | 47 | | [string]$AppName = $null, |
| | 48 | |
|
| | 49 | | [Parameter(Mandatory = $false)] |
| | 50 | | [Serilog.Sinks.Syslog.Facility]$Facility = [Serilog.Sinks.Syslog.Facility]::Local0, |
| | 51 | |
|
| | 52 | | [Parameter(Mandatory = $false)] |
| | 53 | | [string]$OutputTemplate, |
| | 54 | |
|
| | 55 | | [Parameter(Mandatory = $false)] |
| | 56 | | [Serilog.Events.LogEventLevel]$RestrictedToMinimumLevel = [Serilog.Events.LevelAlias]::Minimum, |
| | 57 | | [System.Func``2[Serilog.Events.LogEventLevel, Serilog.Sinks.Syslog.Severity]]$SeverityMapping = $null, |
| | 58 | | [Serilog.Formatting.ITextFormatter]$Formatter = $null, |
| | 59 | | [Serilog.Core.LoggingLevelSwitch]$LevelSwitch = $null |
| | 60 | | ) |
| | 61 | |
|
| | 62 | | process { |
| 0 | 63 | | return [Serilog.SyslogLoggerConfigurationExtensions]::LocalSyslog( |
| | 64 | | $LoggerConfig.WriteTo, # 1 loggerSinkConfig |
| | 65 | | $AppName, # 2 appName |
| | 66 | | $Facility, # 3 facility |
| | 67 | | $OutputTemplate, # 4 outputTemplate |
| | 68 | | $RestrictedToMinimumLevel, # 5 restrictedToMinimumLevel |
| | 69 | | $SeverityMapping, # 6 severityMapping |
| | 70 | | $Formatter, # 7 formatter |
| | 71 | | $LevelSwitch # 8 levelSwitch |
| | 72 | | ) |
| | 73 | | } |
| | 74 | | } |