| | | 1 | | <# |
| | | 2 | | .SYNOPSIS |
| | | 3 | | Starts the Kestrun logger. |
| | | 4 | | .DESCRIPTION |
| | | 5 | | This function initializes the Kestrun logger with specified configurations. |
| | | 6 | | .PARAMETER Name |
| | | 7 | | The name of the logger instance. This is mandatory. |
| | | 8 | | .PARAMETER LoggerConfig |
| | | 9 | | A Serilog logger configuration object to set up the logger. |
| | | 10 | | .PARAMETER MinimumLevel |
| | | 11 | | The minimum log level for the logger. Default is Information. |
| | | 12 | | .PARAMETER Console |
| | | 13 | | If specified, adds a console sink to the logger. |
| | | 14 | | .PARAMETER PowerShell |
| | | 15 | | If specified, adds a PowerShell sink to the logger. |
| | | 16 | | .PARAMETER FilePath |
| | | 17 | | The file path where logs will be written. If not specified, defaults to a predefined path |
| | | 18 | | .PARAMETER FileRollingInterval |
| | | 19 | | The rolling interval for the log file. Default is Infinite. |
| | | 20 | | .PARAMETER SetAsDefault |
| | | 21 | | If specified, sets the created logger as the default logger for Serilog. |
| | | 22 | | .PARAMETER PassThru |
| | | 23 | | If specified, returns the created logger object. |
| | | 24 | | .EXAMPLE |
| | | 25 | | Register-KrLogger -Name "MyLogger" -MinimumLevel Debug -Console -FilePath "C:\Logs\kestrun.log" -FileRollingInte |
| | | 26 | | Initializes the Kestrun logger with Debug level, adds console and file sinks, sets the logger as default, and re |
| | | 27 | | .EXAMPLE |
| | | 28 | | Register-KrLogger -Name "MyLogger" -LoggerConfig $myLoggerConfig -SetAsDefault |
| | | 29 | | Initializes the Kestrun logger using a pre-configured Serilog logger configuration object and sets it as the def |
| | | 30 | | .EXAMPLE |
| | | 31 | | Register-KrLogger -Name "MyLogger" -MinimumLevel Debug -Console -FilePath "C:\Logs\kestrun.log" -FileRollingInte |
| | | 32 | | Initializes the Kestrun logger with Debug level, adds console and file sinks, sets the logger as default, and re |
| | | 33 | | .EXAMPLE |
| | | 34 | | Register-KrLogger -Name "MyLogger" -MinimumLevel Debug -Console -FilePath "C:\Logs\kestrun.log" -FileRollingInte |
| | | 35 | | Initializes the Kestrun logger with Debug level, adds console and file sinks, sets the logger as default, and re |
| | | 36 | | #> |
| | | 37 | | function Register-KrLogger { |
| | | 38 | | [KestrunRuntimeApi('Everywhere')] |
| | | 39 | | [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseShouldProcessForStateChangingFunctions', '')] |
| | | 40 | | [CmdletBinding()] |
| | | 41 | | [OutputType([Serilog.ILogger])] |
| | | 42 | | param( |
| | | 43 | | [Parameter(Mandatory = $true)] |
| | | 44 | | [string]$Name, |
| | | 45 | | |
| | | 46 | | [Parameter(Mandatory = $true, ValueFromPipeline = $true)] |
| | | 47 | | [Serilog.LoggerConfiguration]$LoggerConfig, |
| | | 48 | | |
| | | 49 | | [Parameter(Mandatory = $false)] |
| | | 50 | | [switch]$SetAsDefault, |
| | | 51 | | |
| | | 52 | | [Parameter(Mandatory = $false)] |
| | | 53 | | [switch]$PassThru |
| | | 54 | | ) |
| | | 55 | | |
| | | 56 | | process { |
| | 0 | 57 | | $logger = [Kestrun.Logging.LoggerConfigurationExtensions]::Register($LoggerConfig, $Name, $SetAsDefault.IsPresen |
| | 0 | 58 | | if ($PassThru) { |
| | 0 | 59 | | return $logger |
| | | 60 | | } |
| | | 61 | | } |
| | | 62 | | } |
| | | 63 | | |