Skip to content

Commit 04bb255

Browse files
author
aliostad
committed
issue #270
1 parent 2fb6c4a commit 04bb255

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<Description>CacheCow is an HTTP Caching Library for .NET</Description>
44
<Authors>Ali Kheyrollahi</Authors>
55
<GenerateDocumentationFile>true</GenerateDocumentationFile>
6-
<Version>2.10.0</Version>
6+
<Version>2.11.0</Version>
77
<PackageProjectUrl>https://github.com/aliostad/CacheCow/</PackageProjectUrl>
88
<PackageLicenseExpression>MIT</PackageLicenseExpression>
99
</PropertyGroup>

src/Common/TraceWriter.cs

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,30 @@ namespace CacheCow
77
internal static class TraceWriter
88
{
99
public const string CacheCowTraceSwitch = "CacheCow";
10+
public const string CacheCowTracingEnvVarName = "CacheCow.Tracing.Switch";
11+
private static bool _hasExaminedEnvVars = false;
12+
13+
// ALERT!! THIS NO LONGER WORKS https://github.com/dotnet/runtime/issues/67991
1014
private static readonly TraceSwitch _switch = new TraceSwitch(CacheCowTraceSwitch, "CacheCow Trace Switch");
1115

16+
private static void ExamineEnvVar()
17+
{
18+
var envvarValue = Environment.GetEnvironmentVariable(CacheCowTraceSwitch) ?? "";
19+
if (envvarValue.Length>0)
20+
{
21+
TraceLevel level;
22+
if (Enum.TryParse(envvarValue, out level))
23+
_switch.Level = level;
24+
}
25+
26+
_hasExaminedEnvVars = true;
27+
}
1228

1329
public static void WriteLine(string message, TraceLevel level, params object[] args)
30+
{
1431

15-
//public static void WriteLine(Func<string> message, TraceLevel level, params object[] args)
16-
{
32+
if (!_hasExaminedEnvVars)
33+
ExamineEnvVar();
1734

1835
if (_switch.Level < level)
1936
return;
@@ -26,7 +43,7 @@ public static void WriteLine(string message, TraceLevel level, params object[] a
2643
}
2744
catch
2845
{
29-
// swallow
46+
// swallow
3047
}
3148

3249

0 commit comments

Comments
 (0)