Skip to content
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

Restore removed API from Extensions #85846

Merged
merged 21 commits into from
Jun 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ public partial class MemoryCacheOptions : Microsoft.Extensions.Options.IOptions<
public MemoryCacheOptions() { }
public Microsoft.Extensions.Internal.ISystemClock? Clock { get { throw null; } set { } }
public double CompactionPercentage { get { throw null; } set { } }
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
[System.Obsolete("This property is retained only for compatibility. Remove use and instead call MemoryCache.Compact as needed.", error: true)]
public bool CompactOnMemoryPressure { get; set; }
public System.TimeSpan ExpirationScanFrequency { get { throw null; } set { } }
Microsoft.Extensions.Caching.Memory.MemoryCacheOptions Microsoft.Extensions.Options.IOptions<Microsoft.Extensions.Caching.Memory.MemoryCacheOptions>.Value { get { throw null; } }
public long? SizeLimit { get { throw null; } set { } }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.ComponentModel;
using Microsoft.Extensions.Internal;
using Microsoft.Extensions.Options;

Expand Down Expand Up @@ -42,6 +43,10 @@ public long? SizeLimit
}
}

[EditorBrowsableAttribute(EditorBrowsableState.Never)]
[Obsolete("This property is retained only for compatibility. Remove use and instead call MemoryCache.Compact as needed.", error: true)]
public bool CompactOnMemoryPressure { get; set; }

/// <summary>
/// Gets or sets the amount to compact the cache by when the maximum size is exceeded.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,30 @@ namespace Microsoft.Extensions.Logging
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")]
public static partial class ConsoleLoggerExtensions
{
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
[System.ObsoleteAttribute("This method is retained only for compatibility. The recommended alternative is AddConsole(this ILoggingBuilder builder).", error: true)]
public static Microsoft.Extensions.Logging.ILoggerFactory AddConsole(this Microsoft.Extensions.Logging.ILoggerFactory factory) { throw null; }
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
[System.ObsoleteAttribute("This method is retained only for compatibility. The recommended alternative is AddConsole(this ILoggingBuilder builder).", error: true)]
public static Microsoft.Extensions.Logging.ILoggerFactory AddConsole(this Microsoft.Extensions.Logging.ILoggerFactory factory, Microsoft.Extensions.Configuration.IConfiguration configuration) { throw null; }
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
[System.ObsoleteAttribute("This method is retained only for compatibility. The recommended alternative is AddConsole(this ILoggingBuilder builder).", error: true)]
public static Microsoft.Extensions.Logging.ILoggerFactory AddConsole(this Microsoft.Extensions.Logging.ILoggerFactory factory, Microsoft.Extensions.Logging.Console.IConsoleLoggerSettings settings) { throw null; }
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
[System.ObsoleteAttribute("This method is retained only for compatibility. The recommended alternative is AddConsole(this ILoggingBuilder builder).", error: true)]
public static Microsoft.Extensions.Logging.ILoggerFactory AddConsole(this Microsoft.Extensions.Logging.ILoggerFactory factory, Microsoft.Extensions.Logging.LogLevel minLevel) { throw null; }
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
[System.ObsoleteAttribute("This method is retained only for compatibility. The recommended alternative is AddConsole(this ILoggingBuilder builder).", error: true)]
public static Microsoft.Extensions.Logging.ILoggerFactory AddConsole(this Microsoft.Extensions.Logging.ILoggerFactory factory, Microsoft.Extensions.Logging.LogLevel minLevel, bool includeScopes) { throw null; }
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
[System.ObsoleteAttribute("This method is retained only for compatibility. The recommended alternative is AddConsole(this ILoggingBuilder builder).", error: true)]
public static Microsoft.Extensions.Logging.ILoggerFactory AddConsole(this Microsoft.Extensions.Logging.ILoggerFactory factory, bool includeScopes) { throw null; }
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
[System.ObsoleteAttribute("This method is retained only for compatibility. The recommended alternative is AddConsole(this ILoggingBuilder builder).", error: true)]
public static Microsoft.Extensions.Logging.ILoggerFactory AddConsole(this Microsoft.Extensions.Logging.ILoggerFactory factory, System.Func<string, Microsoft.Extensions.Logging.LogLevel, bool> filter) { throw null; }
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
[System.ObsoleteAttribute("This method is retained only for compatibility. The recommended alternative is AddConsole(this ILoggingBuilder builder).", error: true)]
public static Microsoft.Extensions.Logging.ILoggerFactory AddConsole(this Microsoft.Extensions.Logging.ILoggerFactory factory, System.Func<string, Microsoft.Extensions.Logging.LogLevel, bool> filter, bool includeScopes) { throw null; }
public static Microsoft.Extensions.Logging.ILoggingBuilder AddConsole(this Microsoft.Extensions.Logging.ILoggingBuilder builder) { throw null; }
public static Microsoft.Extensions.Logging.ILoggingBuilder AddConsole(this Microsoft.Extensions.Logging.ILoggingBuilder builder, System.Action<Microsoft.Extensions.Logging.Console.ConsoleLoggerOptions> configure) { throw null; }
[System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("Binding TOptions to configuration values may require generating dynamic code at runtime.")]
Expand All @@ -27,6 +51,16 @@ public static partial class ConsoleLoggerExtensions
}
namespace Microsoft.Extensions.Logging.Console
{
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
[System.ObsoleteAttribute("This type is retained only for compatibility. The recommended alternative is ConsoleLoggerOptions.")]
public partial class ConfigurationConsoleLoggerSettings : Microsoft.Extensions.Logging.Console.IConsoleLoggerSettings
{
public ConfigurationConsoleLoggerSettings(Microsoft.Extensions.Configuration.IConfiguration configuration) { }
public Microsoft.Extensions.Primitives.IChangeToken? ChangeToken { get { throw null; } }
public bool IncludeScopes { get { throw null; } }
public Microsoft.Extensions.Logging.Console.IConsoleLoggerSettings Reload() { throw null; }
public bool TryGetSwitch(string name, out Microsoft.Extensions.Logging.LogLevel level) { throw null; }
}
public abstract partial class ConsoleFormatter
{
protected ConsoleFormatter(string name) { }
Expand Down Expand Up @@ -86,6 +120,27 @@ public enum ConsoleLoggerQueueFullMode
Wait = 0,
DropWrite = 1,
}
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
[System.ObsoleteAttribute("This type is retained only for compatibility. The recommended alternative is ConsoleLoggerOptions.", error: true)]
public partial class ConsoleLoggerSettings : Microsoft.Extensions.Logging.Console.IConsoleLoggerSettings
{
public ConsoleLoggerSettings() { }
public Microsoft.Extensions.Primitives.IChangeToken? ChangeToken { get { throw null; } set { } }
public bool DisableColors { get { throw null; } set { } }
public bool IncludeScopes { get { throw null; } set { } }
public System.Collections.Generic.IDictionary<string, Microsoft.Extensions.Logging.LogLevel> Switches { get { throw null; } set { } }
public Microsoft.Extensions.Logging.Console.IConsoleLoggerSettings Reload() { throw null; }
public bool TryGetSwitch(string name, out Microsoft.Extensions.Logging.LogLevel level) { throw null; }
}
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
[System.ObsoleteAttribute("This type is retained only for compatibility. The recommended alternative is ConsoleLoggerOptions.", error: true)]
public partial interface IConsoleLoggerSettings
{
Microsoft.Extensions.Primitives.IChangeToken? ChangeToken { get; }
bool IncludeScopes { get; }
Microsoft.Extensions.Logging.Console.IConsoleLoggerSettings Reload();
bool TryGetSwitch(string name, out Microsoft.Extensions.Logging.LogLevel level);
}
public partial class JsonConsoleFormatterOptions : Microsoft.Extensions.Logging.Console.ConsoleFormatterOptions
{
public JsonConsoleFormatterOptions() { }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

<ItemGroup>
<ProjectReference Include="$(LibrariesProjectRoot)System.Text.Json\ref\System.Text.Json.csproj" />
<ProjectReference Include="$(LibrariesProjectRoot)Microsoft.Extensions.Configuration.Abstractions\ref\Microsoft.Extensions.Configuration.Abstractions.csproj" />
<ProjectReference Include="$(LibrariesProjectRoot)Microsoft.Extensions.Logging.Abstractions\ref\Microsoft.Extensions.Logging.Abstractions.csproj" />
<ProjectReference Include="$(LibrariesProjectRoot)Microsoft.Extensions.Logging\ref\Microsoft.Extensions.Logging.csproj" />
<ProjectReference Include="$(LibrariesProjectRoot)Microsoft.Extensions.Options\ref\Microsoft.Extensions.Options.csproj" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.ComponentModel;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Primitives;

namespace Microsoft.Extensions.Logging.Console
{
[EditorBrowsable(EditorBrowsableState.Never)]
[Obsolete("This type is retained only for compatibility. The recommended alternative is ConsoleLoggerOptions.")]
public class ConfigurationConsoleLoggerSettings : IConsoleLoggerSettings
{
internal readonly IConfiguration _configuration;

public ConfigurationConsoleLoggerSettings(IConfiguration configuration)
{
_configuration = configuration;
ChangeToken = configuration.GetReloadToken();
}

public IChangeToken? ChangeToken { get; private set; }

public bool IncludeScopes
{
get
{
bool includeScopes;
var value = _configuration["IncludeScopes"];
if (string.IsNullOrEmpty(value))
{
return false;
}
else if (bool.TryParse(value, out includeScopes))
{
return includeScopes;
}
else
{
var message = $"Configuration value '{value}' for setting '{nameof(IncludeScopes)}' is not supported.";
throw new InvalidOperationException(message);
}
}
}

public IConsoleLoggerSettings Reload()
{
ChangeToken = null!;
return new ConfigurationConsoleLoggerSettings(_configuration);
}

public bool TryGetSwitch(string name, out LogLevel level)
{
var switches = _configuration.GetSection("LogLevel");
if (switches == null)
{
level = LogLevel.None;
return false;
}

var value = switches[name];
if (string.IsNullOrEmpty(value))
{
level = LogLevel.None;
return false;
}
else if (Enum.TryParse<LogLevel>(value, true, out level))
{
return true;
}
else
{
var message = $"Configuration value '{value}' for category '{name}' is not supported.";
throw new InvalidOperationException(message);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.ComponentModel;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging.Configuration;
using Microsoft.Extensions.Logging.Console;
using Microsoft.Extensions.Options;
using Microsoft.Extensions.Primitives;

namespace Microsoft.Extensions.Logging
{
public static partial class ConsoleLoggerExtensions
{
[EditorBrowsable(EditorBrowsableState.Never)]
[Obsolete("This method is retained only for compatibility. The recommended alternative is AddConsole(this ILoggingBuilder builder).", error: true)]
public static Logging.ILoggerFactory AddConsole(this Logging.ILoggerFactory factory, Extensions.Configuration.IConfiguration configuration)
{
var settings = new ConfigurationConsoleLoggerSettings(configuration);
return factory.AddConsole(settings);
}

[EditorBrowsable(EditorBrowsableState.Never)]
[Obsolete("This method is retained only for compatibility. The recommended alternative is AddConsole(this ILoggingBuilder builder).", error: true)]
public static Logging.ILoggerFactory AddConsole(this Logging.ILoggerFactory factory, Console.IConsoleLoggerSettings settings)
{
factory.AddProvider(new ConsoleLoggerProvider(ConsoleLoggerSettingsAdapter.GetOptionsMonitor(settings)));
return factory;
}

[EditorBrowsable(EditorBrowsableState.Never)]
[Obsolete("This method is retained only for compatibility. The recommended alternative is AddConsole(this ILoggingBuilder builder).", error: true)]
public static Logging.ILoggerFactory AddConsole(this Logging.ILoggerFactory factory, Logging.LogLevel minLevel, bool includeScopes)
{
factory.AddConsole((n, l) => l >= LogLevel.Information, includeScopes);
return factory;
}

[EditorBrowsable(EditorBrowsableState.Never)]
[Obsolete("This method is retained only for compatibility. The recommended alternative is AddConsole(this ILoggingBuilder builder).", error: true)]
public static Logging.ILoggerFactory AddConsole(this Logging.ILoggerFactory factory, Logging.LogLevel minLevel)
{
factory.AddConsole(minLevel, includeScopes: false);
return factory;
}

[EditorBrowsable(EditorBrowsableState.Never)]
[Obsolete("This method is retained only for compatibility. The recommended alternative is AddConsole(this ILoggingBuilder builder).", error: true)]
public static Logging.ILoggerFactory AddConsole(this Logging.ILoggerFactory factory, bool includeScopes)
{
factory.AddConsole((n, l) => l >= LogLevel.Information, includeScopes);
return factory;
}

[EditorBrowsable(EditorBrowsableState.Never)]
[Obsolete("This method is retained only for compatibility. The recommended alternative is AddConsole(this ILoggingBuilder builder).", error: true)]
public static Logging.ILoggerFactory AddConsole(this Logging.ILoggerFactory factory, System.Func<string, Logging.LogLevel, bool> filter, bool includeScopes)
{
factory.AddConsole(new ConsoleLoggerSettings() { IncludeScopes = includeScopes });
return factory;
}

[EditorBrowsable(EditorBrowsableState.Never)]
[Obsolete("This method is retained only for compatibility. The recommended alternative is AddConsole(this ILoggingBuilder builder).", error: true)]
public static Logging.ILoggerFactory AddConsole(this Logging.ILoggerFactory factory, System.Func<string, Logging.LogLevel, bool> filter)
{
factory.AddConsole(filter, includeScopes: false);
return factory;
}

[EditorBrowsable(EditorBrowsableState.Never)]
[Obsolete("This method is retained only for compatibility. The recommended alternative is AddConsole(this ILoggingBuilder builder).", error: true)]
public static Logging.ILoggerFactory AddConsole(this Logging.ILoggerFactory factory)
{
return factory.AddConsole(includeScopes: false);
}

[Obsolete]
private sealed class ConsoleLoggerSettingsAdapter : IConfigureOptions<ConsoleLoggerOptions>, IOptionsChangeTokenSource<ConsoleLoggerOptions>
{
private IConsoleLoggerSettings _settings;
private ConsoleLoggerSettingsAdapter(IConsoleLoggerSettings settings)
{
_settings = settings;
}

IChangeToken IOptionsChangeTokenSource<ConsoleLoggerOptions>.GetChangeToken() => _settings.ChangeToken ?? NullChangeToken.Instance;

string IOptionsChangeTokenSource<ConsoleLoggerOptions>.Name => Microsoft.Extensions.Options.Options.DefaultName;

void IConfigureOptions<ConsoleLoggerOptions>.Configure(ConsoleLoggerOptions options)
{
options.IncludeScopes = _settings.IncludeScopes;
if (_settings is ConfigurationConsoleLoggerSettings configSettings)
{
options.Configure(configSettings._configuration);
}
else if (_settings is ConsoleLoggerSettings consoleSettings)
{
options.DisableColors = consoleSettings.DisableColors;
}
}

internal static OptionsMonitor<ConsoleLoggerOptions> GetOptionsMonitor(IConsoleLoggerSettings settings)
{
ConsoleLoggerSettingsAdapter adapter = new(settings);
OptionsFactory<ConsoleLoggerOptions> factory = new( new IConfigureOptions<ConsoleLoggerOptions>[] { adapter }, Array.Empty<IPostConfigureOptions<ConsoleLoggerOptions>>());
IOptionsChangeTokenSource<ConsoleLoggerOptions>[] sources = new IOptionsChangeTokenSource<ConsoleLoggerOptions>[] { adapter };
OptionsCache<ConsoleLoggerOptions> cache = new();

return new OptionsMonitor<ConsoleLoggerOptions>(factory, sources, cache);
}
}

private sealed class NullChangeToken : IChangeToken, IDisposable
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NullChangeToken

do we need to mark this as obsolete too? I am seeign we did that with ConsoleLoggerSettingsAdapter

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it's private. I marked ConsoleLoggerSettingsAdapter obsolete because it needed to use other obsolete API. This type does not, so it doesn't need obsolete.

{
internal static NullChangeToken Instance { get; } = new NullChangeToken();
private NullChangeToken() { }
public bool HasChanged => false;
public bool ActiveChangeCallbacks => false;
public IDisposable RegisterChangeCallback(Action<object?> callback, object? state) => this;
public void Dispose() { }
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
namespace Microsoft.Extensions.Logging
{
[UnsupportedOSPlatform("browser")]
public static class ConsoleLoggerExtensions
public static partial class ConsoleLoggerExtensions
{
internal const string RequiresDynamicCodeMessage = "Binding TOptions to configuration values may require generating dynamic code at runtime.";
internal const string TrimmingRequiresUnreferencedCodeMessage = "TOptions's dependent types may have their members trimmed. Ensure all required members are preserved.";
Expand Down
Loading