Set-TraceSource parameter -Option has default value 'None' and not 'All'. #11497
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
PR Summary
In all versions (5.1, 7.2, 7.4, 7.5) i changed mentioned
Set-TraceSource
default value for parameter-Option
. In current documentation is stated that the default value isAll
but is actuallyNone
.I found this when i executed cmdlet
Set-TraceSource -Name * -PSHost
without explicit value for parameter-Option
(expected it will beAll
by default as stated in documentation) but no tracing information was shown when i executed further commands. If i explicitly set the-Option
parameter everything is fine.Here is link for 7.4 where doc says that the default value is
All
https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/set-tracesource?view=powershell-7.4#-option.I went to explore the source code to be sure and it seems to me that one of these things should happen:
private PSTraceSourceOptions _options = PSTraceSourceOptions.All;
toprivate PSTraceSourceOptions _options = PSTraceSourceOptions.None;
because the initially set valuePSTraceSourceOptions.All
is actually never used. You have to explicitly set-Option
parameter otherwise_options
variable is not used thanks to theif (optionsSpecified)
condition. But in that case you overwrite the initially set valuePSTraceSourceOptions.All
so there is no reason to set it as initial value for variable_options
. It makes more sense to set it toPSTraceSourceOptions.None
.if (optionsSpecified) { SetFlags(matchingSources); }
so it is not necessary to explicitly set-Option
parameter and the default value for this parameter will be trullyPSTraceSourceOptions.All
. But this may theoretically lead to problems if anybody uses theSet-TraceSource
cmdlet without-Option
parameter (don't know if it makes sense) because then tracing will magically start to appear.https://github.com/PowerShell/PowerShell/blob/2f4f585e7fe075f5c1669397ae738c554fa18391/src/Microsoft.PowerShell.Commands.Utility/commands/utility/trace/TraceListenerCommandBase.cs#L47
Somewhere later in the file we can see that the initial value
PSTraceSourceOptions.All
from variable_options
is actually never used if it is not explictly specified via cmdlet-Option
parameter.PR Checklist