This note outlines the proposed changes for:
- Enabling logger support in test platform for protocol and C# library based clients.
- Allowing users to provide loggers from the runsettings.
-
Enabling logger support for protocol and C# library based clients will allow clients to use logger extensibility feature.
-
Allowing users to provide loggers from the runsettings enables:
- Protocol and C# library based clients to provide loggers to the test platform.
- Configuring loggers as code. Users can commit a runsettings with required loggers and it doesn't need to be specified at each invocation.
Loggers can be provided to the test platform in one of the following ways:
-
/Logger:"UriOrFriendlyName";Key1=Value1;Key2=Value2
This is a switch to vstest.console.exe that feeds logger information to the test platform. For instance:/Logger:"logger://Microsoft/TestPlatform/TrxLogger/v1"
This loads and initializes logger with "logger://Microsoft/TestPlatform/TrxLogger/v1" as uri.
/Logger:sampleLogger;Key1=Value1;Key1=Value2
This loads and initializes logger with
sampleLogger
as friendly name.Key1=Value1
andKey2=Value2
are passed as dictionary parameters to the logger while initialization. -
Runsettings via
Logger
node in theLoggerRunSettings
section. Here is a sample on how this can be specified:<RunSettings> <LoggerRunSettings> <Loggers> <Logger friendlyName="sampleLoggerwithParameters"> <Configuration> <Key1>Value1</Key1> <Key2>Value2</Key2> </Configuration> </Logger> <Logger uri="logger://sample/sampleLoggerWithoutParameters1" friendlyName="sampleLoggerWithoutParameters1" /> <Logger uri="logger://sample/sampleLoggerWithoutParameters2" assemblyQualifiedName="Sample.Sample.Sample.SampleLogger, Sample.Sample.Logger, Version=0.0.0.0, Culture=neutral, PublicKeyToken=xxxxxxxxxxxxxxxx" friendlyName="sampleLoggerWithoutParameters2" /> </Loggers> </LoggerRunSettings> </RunSettings>
This loads and initializes:
- Logger with
friendlyName="sampleLoggerwithParameters"
.Key1=Value1
andKey2=Value2
are passed as dictionary parameters to the logger while initialization. i.e.SampleLoggerWithParameters.Initialize(TestLoggerEvents events, Dictionary<string, string> parameters)
is invoked withparameters = {{"Key1", "Value1"}, {"Key2", "Value2"}}
- Logger with
uri="logger://sample/sampleLoggerWithoutParameters1"
. FriendlyName is ignored in this case as uri takes more precedence. - Logger with
assemblyQualifiedName="Sample.Sample.Sample.SampleLogger, Sample.Sample.Logger, Version=0.0.0.0, Culture=neutral, PublicKeyToken=xxxxxxxxxxxxxxxx"
. Uri and friendlyName are ignored in this case as assemblyQualifiedName takes more precedence.
- Logger with
Test platform loads custom logger assemblies from test adapter paths and source directory. Check [adapter extensibility] (0004-Adapter-Extensibility.md) to know about how to provide test adapter paths to test platform.
- If same logger is specified both in command line arguments and run settings, command line takes precedence.
- User can override existing logger value in runsettings from command line. For example
vstest.console foo.dll -- LoggerRunSettings.Loggers="<Logger friendlyName=\"sampleLoggerwithParameters\" />"
. - Multiple Loggers can be added in runsettings by adding
Logger
node inLoggerRunSettings.Loggers
section. - Configuration is optional in
Logger
node. - Atleast one attribute among
uri
,friendlyName
,assemblyQualifiedName
should be present inLogger
node. - If more than one attributes among
uri
,friendlyName
,assemblyQualifiedName
are present, then precedence order isassemblyQualifiedName > uri > friendlyName
. Attributes other than precedent attribute are ignored. - Logger can be enabled or disabled using
enabled
attribute inLogger
node. For example to disable a logger:<Logger friendlyName="sampleLogger" enabled="false" />
.
Exception scenarios: In case of exception, test run is aborted. Following are the exception scenarios:
LoggerRunSettings
orLoggers
node has attributes.LoggerRunSettings
has any node other thanLoggers
.Loggers
has any node other thanLogger
.Logger
has any node other thanConfiguration
.Logger
node has any attribute other thanuri
,assemblyQualifiedName
,friendlyName
, orenabled
.- Invalid format
uri
is given. - Unable to find logger using precedent attribute.
- If none of the attributes
uri
,assemblyQualifiedName
,friendlyName
is given.
Warning scenarios:
- Key value pair has empty or whitespace value. Example:
<Key1></Key1>
.
Ignored scenarios:
- Duplicate keys in
Configuration
node is ignored and verbose is added for it.
Following are the proposed design changes for enabling logger support for protocol and C# library based clients:
- TestLoggerManager will manage all the loggers. TestLoggerManager will be responsible for:
- Initializing loggers from the run settings.
- Enabling and triggering logger events.
- Disposing logger events.
- TestEngine API will have GetLoggerManager method which will return new TestLoggerManager instance on every call.
- TestPlatform will get instance from TestEngine and initialize TestLoggerManager and will pass this TestLoggerManager instance to TestRunRequest and DiscoveryRequest.
- TestRunRequest and DiscoveryRequest will hold the TestLoggerManager instance. On receiving any run/discovery events, respective methods of TestLoggerManager will be invoked. i.e. TestLoggerManager will no longer register logger events with run or discovery events.
- On test run/discovery completion, TestLoggerManager will be disposed by TestRunRequest and DiscoveryRequest.
- Limitation with this approach is that if TestRunRequest users like TestRequestManager tries to call
TestRunRequest.ExecuteAsync()
second time, then logger events will not be invoked as TestLoggerManager will already be disposed in first run.