-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Support TraceSource to be initialized from the app.config file #73087
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
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
4727084
Adding NetFx System.Diagnostics config section types
ericstj 6c466bf
WIP : Add API to configure Diagnostics.Tracing
ericstj 7885a77
Get running; add tests
steveharter 1df0a47
Merge branch 'main' of https://github.com/steveharter/runtime into ad…
steveharter ba57e1f
Tests and naming
steveharter 3159c85
Non functional changes - format, comments
steveharter a5ac25d
Fix System.Diagnostics.PerformanceCounter diag overlap
steveharter bb6f232
Revert "Fix System.Diagnostics.PerformanceCounter diag overlap"
steveharter 41c8997
Remove code for perf counter filemappingsize config entry since it wa…
steveharter 939a033
Feedback (non-functional)
steveharter File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
...guration.ConfigurationManager/ref/System.Configuration.ConfigurationManager.netcoreapp.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// ------------------------------------------------------------------------------ | ||
// Changes to this file must follow the https://aka.ms/api-review process. | ||
// ------------------------------------------------------------------------------ | ||
|
||
namespace System.Diagnostics | ||
{ | ||
public static partial class TraceConfiguration | ||
{ | ||
public static void Register() { } | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
213 changes: 213 additions & 0 deletions
213
...tem.Configuration.ConfigurationManager/src/System/Diagnostics/DiagnosticsConfiguration.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,213 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System.Configuration; | ||
using System.Runtime.Versioning; | ||
|
||
namespace System.Diagnostics | ||
{ | ||
internal static class DiagnosticsConfiguration | ||
{ | ||
private static volatile SystemDiagnosticsSection s_configSection; | ||
private static volatile InitState s_initState = InitState.NotInitialized; | ||
|
||
// Setting for Switch.switchSetting | ||
internal static SwitchElementsCollection SwitchSettings | ||
{ | ||
get | ||
{ | ||
Initialize(); | ||
SystemDiagnosticsSection configSectionSav = s_configSection; | ||
return configSectionSav?.Switches; | ||
} | ||
} | ||
|
||
internal static string ConfigFilePath | ||
{ | ||
[ResourceExposure(ResourceScope.Machine)] | ||
[ResourceConsumption(ResourceScope.Machine)] | ||
get | ||
{ | ||
Initialize(); | ||
SystemDiagnosticsSection configSectionSav = s_configSection; | ||
if (configSectionSav != null) | ||
{ | ||
return configSectionSav.ElementInformation.Source; | ||
} | ||
|
||
return string.Empty; // the default | ||
} | ||
} | ||
|
||
// Setting for TraceInternal.AutoFlush | ||
internal static bool AutoFlush | ||
{ | ||
get | ||
{ | ||
Initialize(); | ||
SystemDiagnosticsSection configSectionSav = s_configSection; | ||
if (configSectionSav != null && configSectionSav.Trace != null) | ||
{ | ||
return configSectionSav.Trace.AutoFlush; | ||
} | ||
|
||
return false; // the default | ||
} | ||
} | ||
|
||
// Setting for TraceInternal.UseGlobalLock | ||
internal static bool UseGlobalLock | ||
{ | ||
get | ||
{ | ||
Initialize(); | ||
SystemDiagnosticsSection configSectionSav = s_configSection; | ||
if (configSectionSav != null && configSectionSav.Trace != null) | ||
{ | ||
return configSectionSav.Trace.UseGlobalLock; | ||
} | ||
|
||
return true; // the default | ||
} | ||
} | ||
|
||
// Setting for TraceInternal.IndentSize | ||
internal static int IndentSize | ||
{ | ||
get | ||
{ | ||
Initialize(); | ||
SystemDiagnosticsSection configSectionSav = s_configSection; | ||
if (configSectionSav != null && configSectionSav.Trace != null) | ||
{ | ||
return configSectionSav.Trace.IndentSize; | ||
} | ||
|
||
return 4; // the default | ||
} | ||
} | ||
|
||
internal static ListenerElementsCollection SharedListeners | ||
{ | ||
get | ||
{ | ||
Initialize(); | ||
SystemDiagnosticsSection configSectionSav = s_configSection; | ||
return configSectionSav?.SharedListeners; | ||
} | ||
} | ||
|
||
internal static SourceElementsCollection Sources | ||
{ | ||
get | ||
{ | ||
Initialize(); | ||
SystemDiagnosticsSection configSectionSav = s_configSection; | ||
return configSectionSav?.Sources; | ||
} | ||
} | ||
|
||
internal static SystemDiagnosticsSection SystemDiagnosticsSection | ||
{ | ||
get | ||
{ | ||
Initialize(); | ||
return s_configSection; | ||
} | ||
} | ||
|
||
private static SystemDiagnosticsSection GetConfigSection() | ||
{ | ||
return s_configSection ??= (SystemDiagnosticsSection)PrivilegedConfigurationManager.GetSection("system.diagnostics"); | ||
} | ||
|
||
internal static bool IsInitializing() => s_initState == InitState.Initializing; | ||
internal static bool IsInitialized() => s_initState == InitState.Initialized; | ||
|
||
internal static bool CanInitialize() => (s_initState != InitState.Initializing) && | ||
!ConfigurationManagerInternalFactory.Instance.SetConfigurationSystemInProgress; | ||
|
||
internal static void Initialize() | ||
{ | ||
// Ported from https://referencesource.microsoft.com/#System/compmod/system/diagnostics/DiagnosticsConfiguration.cs,188 | ||
// This port removed the lock on TraceInternal.critSec since that is now in a separate assembly and TraceInternal | ||
// is internal and because GetConfigSection() is not locked elsewhere such as for connection strings. | ||
|
||
// Because some of the code used to load config also uses diagnostics | ||
// we can't block them while we initialize from config. Therefore we just | ||
// return immediately and they just use the default values. | ||
if (s_initState != InitState.NotInitialized || | ||
ConfigurationManagerInternalFactory.Instance.SetConfigurationSystemInProgress) | ||
{ | ||
return; | ||
} | ||
|
||
s_initState = InitState.Initializing; // used for preventing recursion | ||
try | ||
{ | ||
s_configSection = GetConfigSection(); | ||
} | ||
finally | ||
{ | ||
s_initState = InitState.Initialized; | ||
} | ||
} | ||
|
||
internal static void Refresh() | ||
{ | ||
ConfigurationManager.RefreshSection("system.diagnostics"); | ||
|
||
// There might still be some persistant state left behind for | ||
// ConfigPropertyCollection (for ex, swtichelements), probably for perf. | ||
// We need to explicitly cleanup any unrecognized attributes that we | ||
// have added during last deserialization, so that they are re-added | ||
// during the next Config.GetSection properly and we get a chance to | ||
// populate the Attributes collection for re-deserialization. | ||
// Another alternative could be to expose the properties collection | ||
// directly as Attributes collection (currently we keep a local | ||
// hashtable which we explicitly need to keep in sycn and hence the | ||
// cleanup logic below) but the down side of that would be we need to | ||
// explicitly compute what is recognized Vs unrecognized from that | ||
// collection when we expose the unrecognized Attributes publically | ||
SystemDiagnosticsSection configSectionSav = s_configSection; | ||
if (configSectionSav != null) | ||
{ | ||
if (configSectionSav.Switches != null) | ||
{ | ||
foreach (SwitchElement swelem in configSectionSav.Switches) | ||
{ | ||
swelem.ResetProperties(); | ||
} | ||
} | ||
|
||
if (configSectionSav.SharedListeners != null) | ||
{ | ||
foreach (ListenerElement lnelem in configSectionSav.SharedListeners) | ||
{ | ||
lnelem.ResetProperties(); | ||
} | ||
} | ||
|
||
if (configSectionSav.Sources != null) | ||
{ | ||
foreach (SourceElement srelem in configSectionSav.Sources) | ||
{ | ||
srelem.ResetProperties(); | ||
} | ||
} | ||
} | ||
|
||
s_configSection = null; | ||
|
||
s_initState = InitState.NotInitialized; | ||
Initialize(); | ||
} | ||
|
||
private enum InitState | ||
{ | ||
NotInitialized, | ||
Initializing, | ||
Initialized | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.