Skip to content

Commit

Permalink
Get running; add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
steveharter committed Jul 29, 2022
1 parent 6c466bf commit 7885a77
Show file tree
Hide file tree
Showing 53 changed files with 1,238 additions and 692 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>$(NetCoreAppCurrent);$(NetCoreAppMinimum);netstandard2.0;$(NetFrameworkMinimum)</TargetFrameworks>
<Nullable>disable</Nullable>
Expand Down Expand Up @@ -272,7 +272,7 @@ System.Configuration.ConfigurationManager</PackageDescription>
<Compile Include="System\Diagnostics\TraceConfiguration.cs" />
<Compile Include="System\Diagnostics\TraceSection.cs" />
<Compile Include="System\Diagnostics\TypedElement.cs" />
<Compile Include="System\Diagnostics\traceutils.cs" />
<Compile Include="System\Diagnostics\TraceUtils.cs" />
</ItemGroup>

<!-- Since this package is compatible with .NETStandard, it must also ensure its .NETFramework and .NETCoreApp behavior is compatible with its .NETStandard behavior.-->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,26 @@

namespace System.Diagnostics
{
internal enum InitState
{
NotInitialized,
Initializing,
Initialized
}

internal static class DiagnosticsConfiguration
{
private static volatile SystemDiagnosticsSection configSection;
private static volatile InitState initState = InitState.NotInitialized;
private static volatile SystemDiagnosticsSection s_configSection;
private static volatile InitState s_initState = InitState.NotInitialized;

// setting for Switch.switchSetting
// Setting for Switch.switchSetting
internal static SwitchElementsCollection SwitchSettings
{
get
{
Initialize();
SystemDiagnosticsSection configSectionSav = configSection;
SystemDiagnosticsSection configSectionSav = s_configSection;
if (configSectionSav != null)
{
return configSectionSav.Switches;
}
else
{
return null;
}
}
}

Expand All @@ -39,53 +36,61 @@ internal static string ConfigFilePath
get
{
Initialize();
SystemDiagnosticsSection configSectionSav = configSection;
SystemDiagnosticsSection configSectionSav = s_configSection;
if (configSectionSav != null)
{
return configSectionSav.ElementInformation.Source;
else
return string.Empty; // the default
}

return string.Empty; // the default
}
}

// setting for TraceInternal.AutoFlush
// Setting for TraceInternal.AutoFlush
internal static bool AutoFlush
{
get
{
Initialize();
SystemDiagnosticsSection configSectionSav = configSection;
SystemDiagnosticsSection configSectionSav = s_configSection;
if (configSectionSav != null && configSectionSav.Trace != null)
{
return configSectionSav.Trace.AutoFlush;
else
return false; // the default
}

return false; // the default
}
}

// setting for TraceInternal.UseGlobalLock
// Setting for TraceInternal.UseGlobalLock
internal static bool UseGlobalLock
{
get
{
Initialize();
SystemDiagnosticsSection configSectionSav = configSection;
SystemDiagnosticsSection configSectionSav = s_configSection;
if (configSectionSav != null && configSectionSav.Trace != null)
{
return configSectionSav.Trace.UseGlobalLock;
else
return true; // the default
}

return true; // the default
}
}

// setting for TraceInternal.IndentSize
// Setting for TraceInternal.IndentSize
internal static int IndentSize
{
get
{
Initialize();
SystemDiagnosticsSection configSectionSav = configSection;
SystemDiagnosticsSection configSectionSav = s_configSection;
if (configSectionSav != null && configSectionSav.Trace != null)
{
return configSectionSav.Trace.IndentSize;
else
return 4; // the default
}

return 4; // the default
}
}

Expand All @@ -94,11 +99,13 @@ internal static ListenerElementsCollection SharedListeners
get
{
Initialize();
SystemDiagnosticsSection configSectionSav = configSection;
SystemDiagnosticsSection configSectionSav = s_configSection;
if (configSectionSav != null)
{
return configSectionSav.SharedListeners;
else
return null;
}

return null;
}
}

Expand All @@ -107,11 +114,13 @@ internal static SourceElementsCollection Sources
get
{
Initialize();
SystemDiagnosticsSection configSectionSav = configSection;
SystemDiagnosticsSection configSectionSav = s_configSection;
if (configSectionSav != null && configSectionSav.Sources != null)
{
return configSectionSav.Sources;
else
return null;
}

return null;
}
}

Expand All @@ -120,31 +129,21 @@ internal static SystemDiagnosticsSection SystemDiagnosticsSection
get
{
Initialize();
return configSection;
return s_configSection;
}
}

private static SystemDiagnosticsSection GetConfigSection()
{
SystemDiagnosticsSection configSection = (SystemDiagnosticsSection)PrivilegedConfigurationManager.GetSection("system.diagnostics");
return configSection;
}

internal static bool IsInitializing()
{
return initState == InitState.Initializing;
SystemDiagnosticsSection s_configSection = (SystemDiagnosticsSection)PrivilegedConfigurationManager.GetSection("system.diagnostics");
return s_configSection;
}

internal static bool IsInitialized()
{
return initState == InitState.Initialized;
}
internal static bool IsInitializing() => s_initState == InitState.Initializing;
internal static bool IsInitialized() => s_initState == InitState.Initialized;

internal static bool CanInitialize()
{
return (initState != InitState.Initializing) &&
!ConfigurationManagerInternalFactory.Instance.SetConfigurationSystemInProgress;
}
internal static bool CanInitialize() => (s_initState != InitState.Initializing) &&
!ConfigurationManagerInternalFactory.Instance.SetConfigurationSystemInProgress;

internal static void Initialize()
{
Expand All @@ -161,23 +160,21 @@ internal static void Initialize()
// 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 (initState != InitState.NotInitialized ||
ConfigurationManagerInternalFactory.Instance.SetConfigurationSystemInProgress)
if (s_initState != InitState.NotInitialized ||
ConfigurationManagerInternalFactory.Instance.SetConfigurationSystemInProgress)
{

return;
}

initState = InitState.Initializing; // used for preventing recursion
s_initState = InitState.Initializing; // used for preventing recursion
try
{
configSection = GetConfigSection();
s_configSection = GetConfigSection();
}
finally
{
initState = InitState.Initialized;
s_initState = InitState.Initialized;
}
//}
}

internal static void Refresh()
Expand All @@ -196,33 +193,45 @@ internal static void Refresh()
// 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 = configSection;
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();
}
}
}

configSection = null;
s_configSection = null;

initState = InitState.NotInitialized;
s_initState = InitState.NotInitialized;
Initialize();
}

private enum InitState
{
NotInitialized,
Initializing,
Initialized
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ internal TraceFilter RefreshRuntimeObject(TraceFilter filter)
{
if (Type.GetType(TypeName) != filter.GetType() || InitDataChanged(filter))
{
// type or initdata changed
// Type or initdata changed.
_runtimeObject = null;
return GetRuntimeObject();
}
Expand Down
Loading

0 comments on commit 7885a77

Please sign in to comment.