Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/TraceClient/TraceClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,12 @@ public TraceClient(string baseUrl, string application, string version, string ke
_thread.Start();
}

/// <summary>A client that reports nothing. Useful as a default before settings are read.</summary>
/// <summary>
/// A client that reports nothing. Useful as a default before settings are read.
/// Its <see cref="DisabledReason"/> is <see cref="ReasonConfig"/>, or
/// <see cref="ReasonEnvironment"/> when the environment turns reporting off, since
/// the environment is checked first.
/// </summary>
public static TraceClient Disabled()
{
return new TraceClient("http://disabled.invalid", "disabled", "disabled", enabled: false);
Expand Down
14 changes: 14 additions & 0 deletions tests/TraceClient.Tests/TraceClientTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,20 @@ public void DisabledReason_NamesTheConfigFlagOrTheMissingKey()
Assert.Equal("config", TraceClient.Disabled().DisabledReason);
}

[Fact]
public void Disabled_SaysEnvironmentRatherThanConfigWhenTheEnvironmentOptsOut()
{
// Disabled() goes through the same constructor, and the environment
// is checked before enabled: false, so its reason is not always "config".
_environment[TraceClient.EnvDoNotTrack] = "1";

TraceClient client = TraceClient.Disabled();

Assert.False(client.IsEnabled);
Assert.Equal(TraceClient.ReasonEnvironment, client.DisabledReason);
Assert.Null(client.InstallId);
}

[Theory]
[InlineData("")]
[InlineData(" ")]
Expand Down
Loading