Skip to content

Commit dc11bdb

Browse files
authored
Fix 851 - Incorrect logic in SensitiveDataLogger (#852)
1 parent ef6ec96 commit dc11bdb

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

service/Abstractions/Diagnostics/SensitiveDataLogger.cs

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,14 @@ public static class SensitiveDataLogger
1212

1313
public static bool Enabled
1414
{
15-
get
16-
{
17-
return s_enabled;
18-
}
15+
get => s_enabled;
1916
set
2017
{
21-
var env = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");
22-
if (!string.Equals(env, "Development", StringComparison.OrdinalIgnoreCase))
23-
{
24-
#pragma warning disable CA2201
25-
throw new ApplicationException("Sensitive data logging can be enabled only in a development environment. Check ASPNETCORE_ENVIRONMENT env var.");
26-
#pragma warning restore CA0000
27-
}
28-
29-
s_enabled = value && string.Equals(env, "Development", StringComparison.OrdinalIgnoreCase);
18+
if (s_enabled == value) { return; }
19+
20+
if (value) { EnsureDevelopmentEnvironment(); }
21+
22+
s_enabled = value;
3023
}
3124
}
3225

@@ -72,4 +65,13 @@ public static void LogSensitive(
7265

7366
logger.Log(LoggingLevel, eventId, message, args);
7467
}
68+
69+
private static void EnsureDevelopmentEnvironment()
70+
{
71+
var env = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");
72+
if (!string.Equals(env, "Development", StringComparison.OrdinalIgnoreCase))
73+
{
74+
throw new InvalidOperationException("Sensitive data logging can be enabled only in a development environment. Check ASPNETCORE_ENVIRONMENT env var.");
75+
}
76+
}
7577
}

0 commit comments

Comments
 (0)