From 130d7843199a667191659cf2979833fec4d12d10 Mon Sep 17 00:00:00 2001 From: Mark J Price Date: Thu, 29 Jun 2023 15:28:27 +0100 Subject: [PATCH] Fix to work with 7.0.4 --- vs4win/Chapter04/Instrumenting/Instrumenting.csproj | 3 +-- vs4win/Chapter04/Instrumenting/Program.cs | 8 +------- vs4win/Chapter04/Instrumenting/appsettings.json | 5 +++-- vscode/Chapter04/Instrumenting/Instrumenting.csproj | 3 +-- vscode/Chapter04/Instrumenting/Program.cs | 8 +------- vscode/Chapter04/Instrumenting/appsettings.json | 5 +++-- 6 files changed, 10 insertions(+), 22 deletions(-) diff --git a/vs4win/Chapter04/Instrumenting/Instrumenting.csproj b/vs4win/Chapter04/Instrumenting/Instrumenting.csproj index 78f15a8..77d2e01 100644 --- a/vs4win/Chapter04/Instrumenting/Instrumenting.csproj +++ b/vs4win/Chapter04/Instrumenting/Instrumenting.csproj @@ -8,8 +8,7 @@ - - + diff --git a/vs4win/Chapter04/Instrumenting/Program.cs b/vs4win/Chapter04/Instrumenting/Program.cs index 69ed96a..e0eb9ff 100644 --- a/vs4win/Chapter04/Instrumenting/Program.cs +++ b/vs4win/Chapter04/Instrumenting/Program.cs @@ -1,13 +1,6 @@ using System.Diagnostics; -using System.Reflection; using Microsoft.Extensions.Configuration; -Console.WriteLine("Warning! Versions 7.0.3xx and 7.0.4xx have bugs that cause an exception:"); -Console.WriteLine("Microsoft.Extensions.Configuration.Binder version: {0}", - typeof(ConfigurationBinder).Assembly.GetCustomAttribute - ()?.Version); -Console.WriteLine(); - string logPath = Path.Combine(Environment.GetFolderPath( Environment.SpecialFolder.DesktopDirectory), "log.txt"); @@ -52,6 +45,7 @@ configuration.GetSection("PacktSwitch").Bind(ts); // Output the trace switch level from appsettings.json. Console.WriteLine($"Trace switch level: {ts.Level}"); +Console.WriteLine($"Trace switch value: {ts.Value}"); Trace.WriteLineIf(ts.TraceError, "Trace error"); Trace.WriteLineIf(ts.TraceWarning, "Trace warning"); diff --git a/vs4win/Chapter04/Instrumenting/appsettings.json b/vs4win/Chapter04/Instrumenting/appsettings.json index 37790aa..bb7702b 100644 --- a/vs4win/Chapter04/Instrumenting/appsettings.json +++ b/vs4win/Chapter04/Instrumenting/appsettings.json @@ -1,5 +1,6 @@ { "PacktSwitch": { - "Level": "Info" + "Value": "Info", // Must be set to work with 7.0.3 or later. + "Level": "Info" // To work with 7.0.2 or earlier including .NET 6. } -} +} \ No newline at end of file diff --git a/vscode/Chapter04/Instrumenting/Instrumenting.csproj b/vscode/Chapter04/Instrumenting/Instrumenting.csproj index 78f15a8..77d2e01 100644 --- a/vscode/Chapter04/Instrumenting/Instrumenting.csproj +++ b/vscode/Chapter04/Instrumenting/Instrumenting.csproj @@ -8,8 +8,7 @@ - - + diff --git a/vscode/Chapter04/Instrumenting/Program.cs b/vscode/Chapter04/Instrumenting/Program.cs index 69ed96a..e0eb9ff 100644 --- a/vscode/Chapter04/Instrumenting/Program.cs +++ b/vscode/Chapter04/Instrumenting/Program.cs @@ -1,13 +1,6 @@ using System.Diagnostics; -using System.Reflection; using Microsoft.Extensions.Configuration; -Console.WriteLine("Warning! Versions 7.0.3xx and 7.0.4xx have bugs that cause an exception:"); -Console.WriteLine("Microsoft.Extensions.Configuration.Binder version: {0}", - typeof(ConfigurationBinder).Assembly.GetCustomAttribute - ()?.Version); -Console.WriteLine(); - string logPath = Path.Combine(Environment.GetFolderPath( Environment.SpecialFolder.DesktopDirectory), "log.txt"); @@ -52,6 +45,7 @@ configuration.GetSection("PacktSwitch").Bind(ts); // Output the trace switch level from appsettings.json. Console.WriteLine($"Trace switch level: {ts.Level}"); +Console.WriteLine($"Trace switch value: {ts.Value}"); Trace.WriteLineIf(ts.TraceError, "Trace error"); Trace.WriteLineIf(ts.TraceWarning, "Trace warning"); diff --git a/vscode/Chapter04/Instrumenting/appsettings.json b/vscode/Chapter04/Instrumenting/appsettings.json index 37790aa..bb7702b 100644 --- a/vscode/Chapter04/Instrumenting/appsettings.json +++ b/vscode/Chapter04/Instrumenting/appsettings.json @@ -1,5 +1,6 @@ { "PacktSwitch": { - "Level": "Info" + "Value": "Info", // Must be set to work with 7.0.3 or later. + "Level": "Info" // To work with 7.0.2 or earlier including .NET 6. } -} +} \ No newline at end of file