-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Changes from 20 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
01cfe3e
Restore missing API from Extensions
ericstj cc664db
Fix a couple missing interfaces
ericstj c23bad7
Fix EventLog test
ericstj 8078dd5
Undo interface heirarchy change in hosting
ericstj ef06d4a
Add API compat validation for old Extensions baseline
ericstj 8fae371
Bring back less logging API and baseline missing
ericstj 3e69333
Implement obsolete console API
ericstj 19ef703
Fix the download of extensions compat packages
ericstj 0c27916
Remove ConsoleLifetime overload
ericstj bb9c4c7
Update obsolete message on InplaceStringBuilder
ericstj e70d1a6
Fill in implementation of obsolete logging methods
ericstj 6271dc1
Update console->config ref dependency
ericstj f2738b3
Update Obsolete messages and make error
ericstj dc7f9e1
Suppress compat around Obsolete(..., error: true)
ericstj 5f9b5dd
Fix more obsolete messages
ericstj dc99729
Remove ConsoleLoggerProvider ctor overloads
ericstj c29ad96
Omit ConfigurationSection .ctor overload
ericstj 58a8cf4
Remove OptionsWrapper members
ericstj 63c233d
Mark restored obsoleted API as EditorBrowsable=never
ericstj 5bdf838
Remove extensions 2.1 compat infrastructure
ericstj e488389
Remove unused usings
ericstj 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 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 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 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 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
79 changes: 79 additions & 0 deletions
79
src/libraries/Microsoft.Extensions.Logging.Console/src/ConfigurationConsoleLoggerSettings.cs
This file contains 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,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); | ||
} | ||
} | ||
} | ||
} |
126 changes: 126 additions & 0 deletions
126
src/libraries/Microsoft.Extensions.Logging.Console/src/ConsoleLoggerExtensions.Obsolete.cs
This file contains 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,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 | ||
{ | ||
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() { } | ||
} | ||
} | ||
} |
This file contains 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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we need to mark this as obsolete too? I am seeign we did that with
ConsoleLoggerSettingsAdapter
There was a problem hiding this comment.
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.