| | | 1 | | <# |
| | | 2 | | .SYNOPSIS |
| | | 3 | | Broadcasts a log message to all connected SignalR clients. |
| | | 4 | | .DESCRIPTION |
| | | 5 | | This function sends a log message to all connected SignalR clients via the IRealtimeBroadcaster service. |
| | | 6 | | The message is broadcast in real-time to all connected clients listening on the hub. |
| | | 7 | | .PARAMETER Level |
| | | 8 | | The log level (e.g., Information, Warning, Error, Debug, Verbose). |
| | | 9 | | .PARAMETER Message |
| | | 10 | | The log message to broadcast. |
| | | 11 | | .EXAMPLE |
| | | 12 | | Send-KrSignalRLog -Level Information -Message "Server started successfully" |
| | | 13 | | Broadcasts an information log message to all connected SignalR clients. |
| | | 14 | | .EXAMPLE |
| | | 15 | | Send-KrSignalRLog -Level Error -Message "Failed to process request" |
| | | 16 | | Broadcasts an error log message to all connected SignalR clients. |
| | | 17 | | .EXAMPLE |
| | | 18 | | Get-KrServer | Send-KrSignalRLog -Level Warning -Message "High memory usage detected" |
| | | 19 | | Broadcasts a warning log message using the pipeline. |
| | | 20 | | .NOTES |
| | | 21 | | This function requires that SignalR has been configured on the server using Add-KrSignalRHubMiddleware. |
| | | 22 | | The IRealtimeBroadcaster service must be registered for this cmdlet to work. |
| | | 23 | | #> |
| | | 24 | | function Send-KrSignalRLog { |
| | | 25 | | [KestrunRuntimeApi('Everywhere')] |
| | | 26 | | [CmdletBinding()] |
| | | 27 | | param( |
| | | 28 | | [Parameter(Mandatory = $true)] |
| | | 29 | | [ValidateSet('Verbose', 'Debug', 'Information', 'Warning', 'Error', 'Fatal')] |
| | | 30 | | [string]$Level, |
| | | 31 | | |
| | | 32 | | [Parameter(Mandatory = $true)] |
| | | 33 | | [string]$Message |
| | | 34 | | ) |
| | | 35 | | |
| | | 36 | | # Only works inside a route script block where $Context is available |
| | 0 | 37 | | if ($null -ne $Context) { |
| | 0 | 38 | | if ($Context.BroadcastLog($Level, $Message, [System.Threading.CancellationToken]::None)) { |
| | 0 | 39 | | Write-KrLog -Level Debug -Message "Broadcasted log message: $Level - $Message" |
| | | 40 | | return |
| | | 41 | | } else { |
| | 0 | 42 | | Write-KrLog -Level Error -Message 'Failed to broadcast log message: Unknown error' |
| | | 43 | | return |
| | | 44 | | } |
| | | 45 | | } |
| | 0 | 46 | | Write-KrOutsideRouteWarning |
| | | 47 | | } |