| | | 1 | | <# |
| | | 2 | | .SYNOPSIS |
| | | 3 | | Enriches log events with custom property. |
| | | 4 | | .DESCRIPTION |
| | | 5 | | Enriches log events with custom property. For example script name. |
| | | 6 | | .PARAMETER LoggerConfig |
| | | 7 | | Instance of LoggerConfiguration |
| | | 8 | | .PARAMETER Name |
| | | 9 | | The name of the property |
| | | 10 | | .PARAMETER Value |
| | | 11 | | The value of the property |
| | | 12 | | .PARAMETER DestructureObjects |
| | | 13 | | If present, and the value is a non-primitive, non-array type, then the value will be converted to a structure; o |
| | | 14 | | .INPUTS |
| | | 15 | | None |
| | | 16 | | .OUTPUTS |
| | | 17 | | LoggerConfiguration object allowing method chaining |
| | | 18 | | .EXAMPLE |
| | | 19 | | PS> New-KrLogger | Add-KrEnrichProperty -Name ScriptName -Value 'Test' | Add-KrSinkConsole | Register-KrLogger |
| | | 20 | | #> |
| | | 21 | | function Add-KrEnrichProperty { |
| | | 22 | | [KestrunRuntimeApi('Everywhere')] |
| | | 23 | | [OutputType([Serilog.LoggerConfiguration])] |
| | | 24 | | [CmdletBinding()] |
| | | 25 | | param( |
| | | 26 | | [Parameter(Mandatory = $true, ValueFromPipeline = $true)] |
| | | 27 | | [Serilog.LoggerConfiguration]$LoggerConfig, |
| | | 28 | | [Parameter(Mandatory = $true)] |
| | | 29 | | [string]$Name, |
| | | 30 | | [Parameter(Mandatory = $true)] |
| | | 31 | | [object]$Value, |
| | | 32 | | [Parameter()] |
| | | 33 | | [switch]$DestructureObjects |
| | | 34 | | ) |
| | | 35 | | |
| | | 36 | | process { |
| | 0 | 37 | | return $LoggerConfig.Enrich.WithProperty($Name, $Value, $DestructureObjects.IsPresent) |
| | | 38 | | } |
| | | 39 | | } |
| | | 40 | | |