Skip to content

Commit 2ecbe0a

Browse files
committed
Return the log level switches dictionary as is, without any allocation
1 parent db9042f commit 2ecbe0a

File tree

2 files changed

+7
-9
lines changed

2 files changed

+7
-9
lines changed

src/Serilog.Settings.Configuration/Settings/Configuration/LoadedConfiguration.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,14 @@ namespace Serilog.Settings.Configuration;
77
/// </summary>
88
public class LoadedConfiguration
99
{
10-
readonly IDictionary<string, LoggingLevelSwitch> _logLevelSwitches;
11-
12-
internal LoadedConfiguration(IDictionary<string, LoggingLevelSwitch> logLevelSwitches)
10+
internal LoadedConfiguration(IReadOnlyDictionary<string, LoggingLevelSwitch> logLevelSwitches)
1311
{
14-
_logLevelSwitches = logLevelSwitches;
12+
LogLevelSwitches = logLevelSwitches;
1513
}
1614

1715
/// <summary>
1816
/// The log level switches that were loaded from the <c>LevelSwitches</c> section of the configuration.
1917
/// </summary>
20-
/// <remarks>The keys of the dictionary are the name of the switches without the leading <c>$</c> character.</remarks>
21-
public IReadOnlyDictionary<string, LoggingLevelSwitch> LogLevelSwitches => _logLevelSwitches.ToDictionary(e => e.Key.TrimStart('$'), e => e.Value);
18+
/// <remarks>The keys of the dictionary are the name of the switches, including the leading <c>$</c> character.</remarks>
19+
public IReadOnlyDictionary<string, LoggingLevelSwitch> LogLevelSwitches { get; }
2220
}

src/Serilog.Settings.Configuration/Settings/Configuration/ResolutionContext.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ namespace Serilog.Settings.Configuration;
99
/// </summary>
1010
sealed class ResolutionContext
1111
{
12-
readonly IDictionary<string, LoggingLevelSwitch> _declaredLevelSwitches;
13-
readonly IDictionary<string, LoggingFilterSwitchProxy> _declaredFilterSwitches;
12+
readonly Dictionary<string, LoggingLevelSwitch> _declaredLevelSwitches;
13+
readonly Dictionary<string, LoggingFilterSwitchProxy> _declaredFilterSwitches;
1414
readonly IConfiguration _appConfiguration;
1515

1616
public ResolutionContext(IConfiguration appConfiguration = null)
@@ -20,7 +20,7 @@ public ResolutionContext(IConfiguration appConfiguration = null)
2020
_appConfiguration = appConfiguration;
2121
}
2222

23-
public IDictionary<string, LoggingLevelSwitch> LogLevelSwitches => _declaredLevelSwitches;
23+
public IReadOnlyDictionary<string, LoggingLevelSwitch> LogLevelSwitches => _declaredLevelSwitches;
2424

2525
/// <summary>
2626
/// Looks up a switch in the declared LoggingLevelSwitches

0 commit comments

Comments
 (0)