markjprice / cs11dotnet7

Repository for the Packt Publishing book titled "C# 11 and .NET 7 - Modern Cross-Platform Development Fundamentals" by Mark J. Price
566 stars 206 forks source link

"Value" setting is also needed in appsettings.json, Chapter 04 switch trace levels #76

Closed richshi closed 1 year ago

richshi commented 1 year ago

Please check that your issue is not already in the errata aka list of corrections and improvements. Please note that PRs will be ignored because code in the repo must match the print book already published. Please raise an issue instead so I can handle it appropriately. All issues will be entered into the errata once closed. They will also be fixed in the next book edition.

You can delete the note above after reading it. Please complete as much information below as possible so that I can understand and fix the issue quickly. Screenshots can be especially useful. You can drag and drop images into the box. Thank you!

Chapter: 4 Page Number: Section Title: Switching Trace Levels Step Number: Problem to fix: appsettings.json , in addition to "Level", "Value" setting is necessary Suggested solution: add "Value" : "3" Other useful information e.g. OS, coding tools, and so on:

markjprice commented 1 year ago

If you add "Value" then it will not be read. This does not work:

{
  "PacktSwitch": {
    "Level": {
      "Value": "3"
    }
  }
}

This works:

{
  "PacktSwitch": {
    "Level": "3"
  }
}

And this works:

{
  "PacktSwitch": {
    "Level": "Info"
  }
}

When testing, make sure that edits to the appsettings.json file are being properly copied to the output directory or you will get confused. I will add a statement to the code to output the actual contents of the file being processed to make this clearer in the next edition, as shown in the following code:

Console.WriteLine(File.ReadAllText(Path.Combine(
  Directory.GetCurrentDirectory(), "appsettings.json")));
richshi commented 1 year ago

In VSC, I had to add "Value" to the appsettings.json like this: {    "PacktSwitch":{        "Level": "Info",        "Value": "3"    }} Otherwise (with only "Level" : "Info" in the json), the complier will throw an exception like this:

On Thursday, June 29, 2023 at 01:45:08 AM CDT, Mark J. Price ***@***.***> wrote:  

If you add "Value" then it will not be read. This does not work: { "PacktSwitch": { "Level": { "Value": "3" } } }

This works: { "PacktSwitch": { "Level": "3" } }

And this works: { "PacktSwitch": { "Level": "Info" } }

When testing, make sure that edits to the appsettings.json file are being properly copied to the output directory or you will get confused. I will add a statement to the code to output the actual contents of the file being processed to make this clearer in the next edition, as shown in the following code: Console.WriteLine(File.ReadAllText(Path.Combine( Directory.GetCurrentDirectory(), "appsettings.json"))); — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>

richshi commented 1 year ago

It appears to be redundant but the Value [string] setting cannot be ignored when I run the debugging.

On Thursday, June 29, 2023 at 08:35:39 AM CDT, Richard Shi ***@***.***> wrote:  

In VSC, I had to add "Value" to the appsettings.json like this: {    "PacktSwitch":{        "Level": "Info",        "Value": "3"    }} Otherwise (with only "Level" : "Info" in the json), the complier will throw an exception like this:

On Thursday, June 29, 2023 at 01:45:08 AM CDT, Mark J. Price ***@***.***> wrote:  

If you add "Value" then it will not be read. This does not work: { "PacktSwitch": { "Level": { "Value": "3" } } }

This works: { "PacktSwitch": { "Level": "3" } }

And this works: { "PacktSwitch": { "Level": "Info" } }

When testing, make sure that edits to the appsettings.json file are being properly copied to the output directory or you will get confused. I will add a statement to the code to output the actual contents of the file being processed to make this clearer in the next edition, as shown in the following code: Console.WriteLine(File.ReadAllText(Path.Combine( Directory.GetCurrentDirectory(), "appsettings.json"))); — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>

markjprice commented 1 year ago

I've done more research to find out what's going on. I have updated an errata item that I already had about this with the latest information I've found. Hopefully that's the end of it! Thanks!

https://github.com/markjprice/cs11dotnet7/blob/main/docs/errata/errata.md#page-178---reviewing-project-packages

richshi commented 1 year ago

Thank you very much, Sir! On Thursday, June 29, 2023 at 09:21:22 AM CDT, Mark J. Price @.***> wrote:

I've done more research to find out what's going on. I have updated an errata item that I already had about this with the latest information I've found. Hopefully that's the end of it! Thanks!

https://github.com/markjprice/cs11dotnet7/blob/main/docs/errata/errata.md#page-178---reviewing-project-packages

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>