| | 1 | | <# |
| | 2 | | .SYNOPSIS |
| | 3 | | Adds an HTTP sink to the Serilog logger configuration. |
| | 4 | | .DESCRIPTION |
| | 5 | | The Add-SinkHttp function configures a logging sink that sends log events to a specified HTTP endpoint. |
| | 6 | | It allows customization of the request URI, batch posting limit, queue limit, period, formatter, batch formatter |
| | 7 | | .PARAMETER LoggerConfig |
| | 8 | | The Serilog LoggerConfiguration object to which the HTTP sink will be added. |
| | 9 | | .PARAMETER RequestUri |
| | 10 | | The URI of the HTTP endpoint to which log events will be sent. |
| | 11 | | .PARAMETER BatchPostingLimit |
| | 12 | | The maximum number of log events to batch together before sending. Defaults to 1000. |
| | 13 | | .PARAMETER QueueLimit |
| | 14 | | The maximum number of log events to keep in the queue before dropping new events. Defaults to unlimited. |
| | 15 | | .PARAMETER Period |
| | 16 | | The time interval at which to send batched log events. Defaults to 2 seconds. |
| | 17 | | .PARAMETER Formatter |
| | 18 | | The formatter to use for individual log events. Defaults to the JSON formatter. |
| | 19 | | .PARAMETER BatchFormatter |
| | 20 | | The formatter to use for the entire batch of log events. Defaults to the JSON formatter. |
| | 21 | | .PARAMETER RestrictedToMinimumLevel |
| | 22 | | The minimum log level required for events to be sent to the HTTP sink. Defaults to Verbose. |
| | 23 | | .PARAMETER HttpClient |
| | 24 | | The HTTP client to use for sending log events. Defaults to a new instance of HttpClient. |
| | 25 | | .PARAMETER Configuration |
| | 26 | | The configuration to use for the HTTP sink. Defaults to the global configuration. |
| | 27 | | .EXAMPLE |
| | 28 | | Add-SinkHttp -LoggerConfig $config -RequestUri "http://example.com/log" -BatchPostingLimit 500 -QueueLimit 100 - |
| | 29 | | Adds an HTTP sink to the logging system that sends log events to "http://example.com/log" with specified batch s |
| | 30 | | .EXAMPLE |
| | 31 | | Add-SinkHttp -LoggerConfig $config -RequestUri "http://example.com/log" |
| | 32 | | Adds an HTTP sink to the logging system that sends log events to "http://example.com/log" with default settings. |
| | 33 | | .NOTES |
| | 34 | | This function is part of the Kestrun logging infrastructure and should be used to enable HTTP logging. |
| | 35 | | #> |
| | 36 | | function Add-KrSinkHttp { |
| | 37 | | [KestrunRuntimeApi('Everywhere')] |
| | 38 | | [CmdletBinding()] |
| | 39 | | [OutputType([Serilog.LoggerConfiguration])] |
| | 40 | | param( |
| | 41 | | [Parameter(Mandatory = $true, ValueFromPipeline = $true)] |
| | 42 | | [Serilog.LoggerConfiguration]$LoggerConfig, |
| | 43 | |
|
| | 44 | | [Parameter(Mandatory = $true)] |
| | 45 | | [string]$RequestUri, |
| | 46 | |
|
| | 47 | | [Parameter(Mandatory = $false)] |
| | 48 | | [int]$BatchPostingLimit = 1000, |
| | 49 | |
|
| | 50 | | [Parameter(Mandatory = $false)] |
| | 51 | | [Nullable[System.Int32]]$QueueLimit = $null, |
| | 52 | |
|
| | 53 | | [Parameter(Mandatory = $false)] |
| | 54 | | [Nullable[System.TimeSpan]]$Period = $null, |
| | 55 | |
|
| | 56 | | [Parameter(Mandatory = $false)] |
| | 57 | | [Serilog.Formatting.ITextFormatter]$Formatter = $null, |
| | 58 | |
|
| | 59 | | [Parameter(Mandatory = $false)] |
| | 60 | | [Serilog.Sinks.Http.IBatchFormatter]$BatchFormatter = $null, |
| | 61 | |
|
| | 62 | | [Serilog.Events.LogEventLevel]$RestrictedToMinimumLevel = [Serilog.Events.LogEventLevel]::Verbose, |
| | 63 | |
|
| | 64 | | [Parameter(Mandatory = $false)] |
| | 65 | | [Serilog.Sinks.Http.IHttpClient]$HttpClient = $null, |
| | 66 | |
|
| | 67 | | [Parameter(Mandatory = $false)] |
| | 68 | | [Microsoft.Extensions.Configuration.IConfiguration]$Configuration = $null |
| | 69 | | ) |
| | 70 | | process { |
| 0 | 71 | | return [Serilog.LoggerSinkConfigurationExtensions]::Http($LoggerConfig.WriteTo, |
| | 72 | | $RequestUri, |
| | 73 | | $BatchPostingLimit, |
| | 74 | | $QueueLimit, |
| | 75 | | $Period, |
| | 76 | | $Formatter, |
| | 77 | | $BatchFormatter, |
| | 78 | | $RestrictedToMinimumLevel, |
| | 79 | | $HttpClient, |
| | 80 | | $Configuration |
| | 81 | | ) |
| | 82 | | } |
| | 83 | | } |
| | 84 | |
|