-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TraceSwitch value is not read from config #7970
Comments
I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label. |
Tagging subscribers to this area: @tommcdon Issue DetailsDescriptionUnlike what docs TraceSwitch value is not read from app.config. I have created a repro here: https://github.com/aliostad/TraceSwitchDoesNotWork Reproduction StepsAdd system.diagnostics switch to the config and then in the code create a As in the repro https://github.com/aliostad/TraceSwitchDoesNotWork Expected behaviorReading value Error (1) Actual behaviorReading value Off (0) - perhaps just the default Regression?I tried netcoreapp3.1 and it was the same Known WorkaroundsNone Configuration.NET 6.0 on mac, x64 Other informationNo response
|
Sorry to be the bearer of bad news, this is a known limitation on .NET Core relative to .NET Framework even though the documentation of the change appears lacking. .NET Core stopped using app.config files in general and one of the repercussions is that this Trace configuration feature is no longer available. Hunting for docs I found a reference tucked away in a doc for migrating WinForms apps: https://docs.microsoft.com/en-us/dotnet/desktop/winforms/migration/?view=netdesktop-6.0#edit-appconfig and there are various 3rd party blog posts, but I think it would be more appropriate if we included it in our breaking changes docs as well as any tracing API docs that are talking about this capability. @maryamariyan I'd suggest we use this issue to track adding that missing documentation to help .NET developers be aware of this change. Some potential options for working around the limitation:
|
Hi @noahfalk Thanks for the detailed and quick answer. Resolved quicker than I expected and a Happy Easter to you. Yet, I hope you would not mind me feeling frustrated by the status of this - and a bit of a rant. When the ASP.NET team in .NET Core demolished what had been built before to enable a much richer application configuration, they really ignored the fact that app.config was way beyond an application configuration concern, it provided the whole framework with knobs. Whether these were worth keeping or not is a separate conversation but they should have been upfront in their design where these other capabilities should go or just dropped. None of the options really appeal to me as a Library developer, not an application developer. Setting up configuration, is a responsibility of the application - and they are free to use whatever means they are comfortable with. Yet for the libraries and the framework, they should be oblivious to such diverse cases and instead rely on a consistent means of configuration CacheCow that has been deployed to production in dozens of places had defined a tracing switch so the consumers can turn on and off. Now for me back to drawing board to think of an alternative. That was for me. But for others, please fix the docs to save them those many hours that I wasted trying so many different combinations. Having said all of above, I might have missed something obvious and would be good to perhaps point out to me a reference or an example of how the library developers are meant to align to the new configuration. Thanks |
This was fixed in .NET 7.0 but the fix requires the application to call TraceConfiguration.Register explicitly. See:
Although the TraceConfiguration.Register documentation mainly talks about TraceSource, the method adds a handler to the Switch.Initializing event, so it applies to TraceSwitch as well. I think the documentation pages that were edited in #7979 should now be changed to mention TraceConfiguration.Register, and this issue should be kept open until that. |
Description
Unlike what docs TraceSwitch value is not read from app.config.
I have created a repro here: https://github.com/aliostad/TraceSwitchDoesNotWork
Reproduction Steps
Add system.diagnostics switch to the config and then in the code create a
TraceSwitch
with that name. Value is not read.As in the repro https://github.com/aliostad/TraceSwitchDoesNotWork
Expected behavior
Reading value Error (1)
Actual behavior
Reading value Off (0) - perhaps just the default
Regression?
I tried netcoreapp3.1 and it was the same
Known Workarounds
None
Configuration
.NET 6.0 on mac, x64
Other information
No response
The text was updated successfully, but these errors were encountered: