Write PodeErrorLog - mdaneri/Pode GitHub Wiki
Logs an Exception, ErrorRecord, or a custom error message using Pode's built-in logging mechanism.
Write-PodeErrorLog -Exception <Exception> [-Level <String>] [-CheckInnerException] [-ThreadId <Int32>]
[-Tag <String>] [-SuppressDefaultLog] [-ProgressAction <ActionPreference>] [<CommonParameters>]
Write-PodeErrorLog -ErrorRecord <ErrorRecord> [-Level <String>] [-ThreadId <Int32>] [-Tag <String>]
[-SuppressDefaultLog] [-ProgressAction <ActionPreference>] [<CommonParameters>]
This function logs exceptions, error records, or custom error messages with optional error categories and levels. It can also log inner exceptions and associate the error with a specific thread ID. Error levels can be set, and inner exceptions can be checked for more detailed logging.
try {
# Some operation
} catch {
$_ | Write-PodeErrorLog
}
[System.Exception]::new('Custom error message') | Write-PodeErrorLog -CheckInnerException
If specified, logs any inner exceptions associated with the provided exception.
Type: SwitchParameter
Parameter Sets: Exception
Aliases:
Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: False
The error record to log. This is used when handling errors through PowerShell's error handling mechanism.
Type: ErrorRecord
Parameter Sets: ErrorRecord
Aliases:
Required: True
Position: Named
Default value: None
Accept pipeline input: True (ByValue)
Accept wildcard characters: False
The exception object to log. This is used when logging caught exceptions.
Type: Exception
Parameter Sets: Exception
Aliases:
Required: True
Position: Named
Default value: None
Accept pipeline input: True (ByValue)
Accept wildcard characters: False
The logging level for the error. Supported levels are: Error, Warning, Informational, Verbose, Debug (Default: Error).
Type: String
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: Error
Accept pipeline input: False
Accept wildcard characters: False
{{ Fill ProgressAction Description }}
Type: ActionPreference
Parameter Sets: (All)
Aliases: proga
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
A switch to suppress writing the error to the default log.
Type: SwitchParameter
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: False
A string that identifies the source application, service, or process generating the log message. The tag helps distinguish log messages from different sources, making it easier to filter and analyze logs. Default is '-'.
Type: String
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: -
Accept pipeline input: False
Accept wildcard characters: False
The ID of the thread where the error occurred. If not specified, the current thread's ID is used.
Type: Int32
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: 0
Accept pipeline input: False
Accept wildcard characters: False
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.