functions/sinks/Add-SinkSyslogLocal.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
function Add-SinkSyslogLocal {
    <#
    .SYNOPSIS
        Writes log events to syslog server
    .DESCRIPTION
        Writes log events to syslog server
    .PARAMETER LoggerConfig
        Instance of LoggerConfiguration
    .PARAMETER AppName
        The name of the application. Defaults to the current process name
    .PARAMETER Facility
        The category of the application
    .PARAMETER OutputTemplate
        A message template describing the format used to write to the sink.
    .PARAMETER RestrictedToMinimumLevel
        The minimum level for events passed through the sink. Ignored when LevelSwitch is specified.
    .INPUTS
        Instance of LoggerConfiguration
    .OUTPUTS
        LoggerConfiguration object allowing method chaining
    .EXAMPLE
        PS> Add-SinkSyslogTcp -Hostname 'syslogServer1'
    #>


    [Cmdletbinding()]
    param(
        [Parameter(Mandatory = $true, ValueFromPipeline = $true)]
        [Serilog.LoggerConfiguration]$LoggerConfig,

        [Parameter(Mandatory = $false)]
        [string]$AppName = $null,

        [Parameter(Mandatory = $false)]
        [Serilog.Sinks.Syslog.Facility]$Facility = [Serilog.Sinks.Syslog.Facility]::Local0,

        [Parameter(Mandatory = $false)]
        [string]$OutputTemplate = '{Message}{NewLine}{Exception}{ErrorRecord}',

        [Parameter(Mandatory = $false)]
        [Serilog.Events.LogEventLevel]$RestrictedToMinimumLevel = [Serilog.Events.LogEventLevel]::Verbose
    )

    process {    
        $LoggerConfig = [Serilog.SyslogLoggerConfigurationExtensions]::LocalSyslog($LoggerConfig.WriteTo,
            $AppName,
            $Facility,
            $OutputTemplate,
            $RestrictedToMinimumLevel
        )

        $LoggerConfig
    }
}