Proxy functions that overwrite the following built-in Write-* cmdlets and add additional logging (features):
Write-VerboseWrite-WarningWrite-InformationWrite-Output(uses$PSCmdlet.WriteObject()instead of steppable pipeline — avoids deadlock on Azure Automation)Write-Error(not a steppable proxy; uses$PSCmdlet.WriteError()with a syntheticErrorRecord)Write-Debug(avoid using Write-Host)Write-Host
Define features (e.g. LogFile, see Data\PSLogProxy.Features.ps1) which will be called on every Write-* invocation using private functions (e.g. Write-LogFile, see Private\Write-LogFile.ps1).
Get-PSLogProxyFeatureEnable-PSLogProxyFeatureDisable-PSLogProxyFeatureGet-PSLogProxyFeatureSettingSet-PSLogProxyFeatureSettingGet-PSLogProxySettingSet-PSLogProxySetting
See Usage for examples.
Additionally makes an API call on every enabled log function invocation.
Disabled by default.
The full URI, e.g. 'https://sb-api-mock.azurewebsites.net/log'
HTTP method, e.g. 'POST'
ScriptBlock string evaluated at runtime. Variables $Type and $Message are available.
e.g. '@{"level"=$Type; "message"=$Message}'
If $true, adds the DateTimeString (ScriptBlock defined in Settings) to the feature message.
If $true, adds the stream noun (e.g. Warning) to the feature message. Defaults to $true on LogFile only.
If $true, adds the calling script leaf name ($MyInvocation.ScriptName) as a prefix to the feature message.
Array of regex patterns. If any match the message, the feature is skipped for that invocation. Defined on Seq by default (empty array).
Additionally logs all messages to a logfile (UNC path) with a universal sortable datetime stamp.
Cannot be used on Azure Automation workers.
Disabled by default.
UNC path to the logfile, default: "C:\temp\PSLogProxy.log"
Sends log events to a Seq log server via HTTP.
Disabled by default.
The full URI of the Seq ingest endpoint. Must be set via Set-PSLogProxyFeatureSetting.
HTTP method, default: 'POST'
ScriptBlock string evaluated at runtime to produce the request body. Has access to $Type, $Message, and $FeatureSettings.
Hashtable of additional properties sent with each event, e.g. @{text=''}. Can be extended at runtime via Set-PSLogProxyFeatureSetting.
Add a new [PSLogProxyFeature] object to the $Script:PSLogProxyFeature array in Data\PSLogProxy.Features.ps1 with Name, Enabled, and CommandString.
When a feature is enabled, its CommandString is called for every Write-* invocation. Before execution, the following placeholders are replaced:
{{Stream}}— noun of the proxy function (e.g.VerboseinWrite-Verbose){{Message}}— the message passed to the proxy function
Add a matching private function in Private\ for use in CommandString.
ScriptBlock invoked during Write-* calls to produce the datetime prefix string, default: {get-date -format u}
Boolean. If $true, adds the DateTimeString to the PowerShell stream message. Default: $false
Boolean. If $true, adds the calling script leaf name ($MyInvocation.ScriptName) as a prefix to the stream message. Default: $true
String used to join prefixes, default: ' | '
Import the module to overwrite the built-in functions. If any feature is enabled, a verbose message is written on import (even if $VerbosePreference is SilentlyContinue):
2023-02-14 10:57:28Z | Verbose | PSLogProxy Module activated on Computer1 with UserName1 (Enabled Feature: LogFile)
Once loaded, use the proxy functions normally — enabled features are invoked automatically.
# Enable LogFile feature
Enable-PSLogProxyFeature -Name LogFile
# Disable LogFile feature
Disable-PSLogProxyFeature -Name LogFile# Change the log file path for the LogFile feature
Get-PSLogProxyFeature -Name "LogFile" | Set-PSLogProxyFeatureSetting -Name "LogFile" -Value "C:\temp\PSLogProxy.log"# Change DateTimeString to Swiss format
Set-PSLogProxySetting -DateTimeString {Get-Date -Format "dd.MM.yyyy HH:mm:ss"}- Additional
"Setting WindowTitle: log [main] - PowerShell 7.3 (xxx)"debug output may appear in some PS7 hosts.
- Does not work on Azure Automation (PS5.1).