Skip to content

Logging is initialized before the configuration file is processed. #6085

@dantraMSFT

Description

@dantraMSFT

On Unix systems (Linux and MacOS), PowerShell logging can be customized using the -settingsFile command-line option and it is assumed the file is processed before any logging occurs.

On recent builds, this is no longer the case and logging is being initialized before the logging overrides are read from the configuration file resulting in logging using the default values.

Note that logging initialization is currently through static constructors and any reference to the associated classes can cause initialization to occur. As a result, logging initialization is non-deterministic and can occur before logging overrides are processed.

Steps to reproduce

Create a powershell.config.json with a single configuration setting "LogIdentity": "CustomPWSH"
Launch PowerShell with -settingsFile powershell.config.json

Expected behavior

On Linux, PowerShell logs all events using the identity 'CustomPWSH'

Actual behavior

PowerShell logs all events using the default identity 'powershell'

Environment data

> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      6.0.1
PSEdition                      Core
GitCommitId                    v6.0.1
OS                             Linux 4.9.0-4-amd64 #1 SMP Debian 4.9.65-3+deb9u1 (2017-12-23)
Platform                       Unix
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Metadata

Metadata

Assignees

Labels

Issue-BugIssue has been identified as a bug in the productResolution-FixedThe issue is fixed.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions