Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
Prev Previous commit
Next Next commit
Rename to XConsoleLog...
  • Loading branch information
maryamariyan committed May 15, 2020
commit fb74d57d9d15355495bf3af5cea1e4b26c9509e8
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ public static partial class ConsoleLoggerExtensions
{
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; }
public static Microsoft.Extensions.Logging.ILoggingBuilder AddLogFormatter<TFormatter, TOptions>(this Microsoft.Extensions.Logging.ILoggingBuilder builder) where TFormatter : class, Microsoft.Extensions.Logging.Console.ILogFormatter where TOptions : class { throw null; }
public static Microsoft.Extensions.Logging.ILoggingBuilder AddLogFormatter<TFormatter, TOptions>(this Microsoft.Extensions.Logging.ILoggingBuilder builder, System.Action<TOptions> configure) where TFormatter : class, Microsoft.Extensions.Logging.Console.ILogFormatter where TOptions : class { throw null; }
public static Microsoft.Extensions.Logging.ILoggingBuilder AddConsoleLogFormatter<TFormatter, TOptions>(this Microsoft.Extensions.Logging.ILoggingBuilder builder) where TFormatter : class, Microsoft.Extensions.Logging.Console.IConsoleLogFormatter where TOptions : class { throw null; }
public static Microsoft.Extensions.Logging.ILoggingBuilder AddConsoleLogFormatter<TFormatter, TOptions>(this Microsoft.Extensions.Logging.ILoggingBuilder builder, System.Action<TOptions> configure) where TFormatter : class, Microsoft.Extensions.Logging.Console.IConsoleLogFormatter where TOptions : class { throw null; }
}
}
namespace Microsoft.Extensions.Logging.Console
Expand Down Expand Up @@ -40,7 +40,7 @@ public ConsoleLoggerOptions() { }
[Microsoft.Extensions.Logging.ProviderAliasAttribute("Console")]
public partial class ConsoleLoggerProvider : Microsoft.Extensions.Logging.ILoggerProvider, Microsoft.Extensions.Logging.ISupportExternalScope, System.IDisposable
{
public ConsoleLoggerProvider(Microsoft.Extensions.Options.IOptionsMonitor<Microsoft.Extensions.Logging.Console.ConsoleLoggerOptions> options, System.Collections.Generic.IEnumerable<Microsoft.Extensions.Logging.Console.ILogFormatter> formatters) { }
public ConsoleLoggerProvider(Microsoft.Extensions.Options.IOptionsMonitor<Microsoft.Extensions.Logging.Console.ConsoleLoggerOptions> options, System.Collections.Generic.IEnumerable<Microsoft.Extensions.Logging.Console.IConsoleLogFormatter> formatters) { }
public Microsoft.Extensions.Logging.ILogger CreateLogger(string name) { throw null; }
public void Dispose() { }
public void SetScopeProvider(Microsoft.Extensions.Logging.IExternalScopeProvider scopeProvider) { }
Expand All @@ -52,48 +52,42 @@ public readonly partial struct ConsoleMessage
public readonly System.ConsoleColor? Foreground;
public ConsoleMessage(string message, System.ConsoleColor? background = default(System.ConsoleColor?), System.ConsoleColor? foreground = default(System.ConsoleColor?)) { throw null; }
}
public partial class DefaultLogFormatter : Microsoft.Extensions.Logging.Console.ILogFormatter, System.IDisposable
public partial class DefaultConsoleLogFormatter : Microsoft.Extensions.Logging.Console.IConsoleLogFormatter, System.IDisposable
{
public DefaultLogFormatter(Microsoft.Extensions.Options.IOptionsMonitor<Microsoft.Extensions.Logging.Console.DefaultLogFormatterOptions> options) { }
public Microsoft.Extensions.Logging.Console.DefaultLogFormatterOptions FormatterOptions { get { throw null; } set { } }
public DefaultConsoleLogFormatter(Microsoft.Extensions.Options.IOptionsMonitor<Microsoft.Extensions.Logging.Console.DefaultConsoleLogFormatterOptions> options) { }
public Microsoft.Extensions.Logging.Console.DefaultConsoleLogFormatterOptions FormatterOptions { get { throw null; } set { } }
public string Name { get { throw null; } }
public void Dispose() { }
public Microsoft.Extensions.Logging.Console.LogMessageEntry Format(Microsoft.Extensions.Logging.LogLevel logLevel, string logName, int eventId, string message, System.Exception exception, Microsoft.Extensions.Logging.IExternalScopeProvider scopeProvider) { throw null; }
public Microsoft.Extensions.Logging.Console.LogMessageEntry Format<TState>(Microsoft.Extensions.Logging.LogLevel logLevel, string logName, int eventId, TState state, System.Exception exception, System.Func<TState, System.Exception, string> formatter, Microsoft.Extensions.Logging.IExternalScopeProvider scopeProvider) { throw null; }
}
public partial class DefaultLogFormatterOptions
public partial class DefaultConsoleLogFormatterOptions
{
public DefaultLogFormatterOptions() { }
public DefaultConsoleLogFormatterOptions() { }
public bool DisableColors { get { throw null; } set { } }
public bool IncludeScopes { get { throw null; } set { } }
public Microsoft.Extensions.Logging.LogLevel LogToStandardErrorThreshold { get { throw null; } set { } }
public string TimestampFormat { get { throw null; } set { } }
public bool UseUtcTimestamp { get { throw null; } set { } }
}
public partial interface IConsole
{
void Flush();
void Write(string message, System.ConsoleColor? background, System.ConsoleColor? foreground);
void WriteLine(string message, System.ConsoleColor? background, System.ConsoleColor? foreground);
}
public partial interface ILogFormatter
public partial interface IConsoleLogFormatter
{
string Name { get; }
Microsoft.Extensions.Logging.Console.LogMessageEntry Format(Microsoft.Extensions.Logging.LogLevel logLevel, string logName, int eventId, string message, System.Exception exception, Microsoft.Extensions.Logging.IExternalScopeProvider scopeProvider);
Microsoft.Extensions.Logging.Console.LogMessageEntry Format<TState>(Microsoft.Extensions.Logging.LogLevel logLevel, string logName, int eventId, TState state, System.Exception exception, System.Func<TState, System.Exception, string> formatter, Microsoft.Extensions.Logging.IExternalScopeProvider scopeProvider);

Choose a reason for hiding this comment

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

Should we simplify the ctor and move ScopeProvider into the service container?

}
public partial class JsonConsoleLogFormatter : Microsoft.Extensions.Logging.Console.ILogFormatter, System.IDisposable
public partial class JsonConsoleLogFormatter : Microsoft.Extensions.Logging.Console.IConsoleLogFormatter, System.IDisposable
{
public JsonConsoleLogFormatter(Microsoft.Extensions.Options.IOptionsMonitor<Microsoft.Extensions.Logging.Console.JsonLogFormatterOptions> options) { }
public Microsoft.Extensions.Logging.Console.JsonLogFormatterOptions FormatterOptions { get { throw null; } set { } }
public JsonConsoleLogFormatter(Microsoft.Extensions.Options.IOptionsMonitor<Microsoft.Extensions.Logging.Console.JsonConsoleLogFormatterOptions> options) { }
public Microsoft.Extensions.Logging.Console.JsonConsoleLogFormatterOptions FormatterOptions { get { throw null; } set { } }
public string Name { get { throw null; } }
public void Dispose() { }
public Microsoft.Extensions.Logging.Console.LogMessageEntry Format(Microsoft.Extensions.Logging.LogLevel logLevel, string logName, int eventId, string message, System.Exception exception, Microsoft.Extensions.Logging.IExternalScopeProvider scopeProvider) { throw null; }
public Microsoft.Extensions.Logging.Console.LogMessageEntry Format<TState>(Microsoft.Extensions.Logging.LogLevel logLevel, string logName, int eventId, TState state, System.Exception exception, System.Func<TState, System.Exception, string> formatter, Microsoft.Extensions.Logging.IExternalScopeProvider scopeProvider) { throw null; }
}
public partial class JsonLogFormatterOptions
public partial class JsonConsoleLogFormatterOptions
{
public JsonLogFormatterOptions() { }
public JsonConsoleLogFormatterOptions() { }
public bool IncludeScopes { get { throw null; } set { } }
public System.Text.Json.JsonSerializerOptions JsonSerializerOptions { get { throw null; } set { } }
public System.Text.Json.JsonWriterOptions JsonWriterOptions { get { throw null; } set { } }
Expand All @@ -107,18 +101,18 @@ public readonly partial struct LogMessageEntry
public readonly Microsoft.Extensions.Logging.Console.ConsoleMessage[] Messages;
public LogMessageEntry(Microsoft.Extensions.Logging.Console.ConsoleMessage[] messages, bool logAsError = false) { throw null; }
}
public partial class SystemdLogFormatter : Microsoft.Extensions.Logging.Console.ILogFormatter, System.IDisposable
public partial class SystemdConsoleLogFormatter : Microsoft.Extensions.Logging.Console.IConsoleLogFormatter, System.IDisposable
{
public SystemdLogFormatter(Microsoft.Extensions.Options.IOptionsMonitor<Microsoft.Extensions.Logging.Console.SystemdLogFormatterOptions> options) { }
public Microsoft.Extensions.Logging.Console.SystemdLogFormatterOptions FormatterOptions { get { throw null; } set { } }
public SystemdConsoleLogFormatter(Microsoft.Extensions.Options.IOptionsMonitor<Microsoft.Extensions.Logging.Console.SystemdConsoleLogFormatterOptions> options) { }
public Microsoft.Extensions.Logging.Console.SystemdConsoleLogFormatterOptions FormatterOptions { get { throw null; } set { } }
public string Name { get { throw null; } }
public void Dispose() { }
public Microsoft.Extensions.Logging.Console.LogMessageEntry Format(Microsoft.Extensions.Logging.LogLevel logLevel, string logName, int eventId, string message, System.Exception exception, Microsoft.Extensions.Logging.IExternalScopeProvider scopeProvider) { throw null; }
public Microsoft.Extensions.Logging.Console.LogMessageEntry Format<TState>(Microsoft.Extensions.Logging.LogLevel logLevel, string logName, int eventId, TState state, System.Exception exception, System.Func<TState, System.Exception, string> formatter, Microsoft.Extensions.Logging.IExternalScopeProvider scopeProvider) { throw null; }
}
public partial class SystemdLogFormatterOptions
public partial class SystemdConsoleLogFormatterOptions
{
public SystemdLogFormatterOptions() { }
public SystemdConsoleLogFormatterOptions() { }
public bool IncludeScopes { get { throw null; } set { } }
public Microsoft.Extensions.Logging.LogLevel LogToStandardErrorThreshold { get { throw null; } set { } }
public string TimestampFormat { get { throw null; } set { } }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ internal ConsoleLogger(string name, ConsoleLoggerProcessor loggerProcessor)

internal IExternalScopeProvider ScopeProvider { get; set; }

internal ILogFormatter Formatter { get; set; }
internal IConsoleLogFormatter Formatter { get; set; }

public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func<TState, Exception, string> formatter)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ public static ILoggingBuilder AddConsole(this ILoggingBuilder builder)
{
builder.AddConfiguration();

builder.AddLogFormatter<JsonConsoleLogFormatter, JsonLogFormatterOptions>();
builder.AddLogFormatter<DefaultLogFormatter, DefaultLogFormatterOptions>();
builder.AddLogFormatter<SystemdLogFormatter, SystemdLogFormatterOptions>();
builder.AddLogFormatter<CompactLogFormatter, CompactLogFormatterOptions>();
builder.AddConsoleLogFormatter<JsonConsoleLogFormatter, JsonConsoleLogFormatterOptions>();
builder.AddConsoleLogFormatter<DefaultConsoleLogFormatter, DefaultConsoleLogFormatterOptions>();
builder.AddConsoleLogFormatter<SystemdConsoleLogFormatter, SystemdConsoleLogFormatterOptions>();
builder.AddConsoleLogFormatter<CompactLogFormatter, CompactLogFormatterOptions>();

builder.Services.TryAddEnumerable(ServiceDescriptor.Singleton<ILoggerProvider, ConsoleLoggerProvider>());
LoggerProviderOptions.RegisterProviderOptions<ConsoleLoggerOptions, ConsoleLoggerProvider>(builder.Services);
Expand All @@ -58,13 +58,13 @@ public static ILoggingBuilder AddConsole(this ILoggingBuilder builder, Action<Co
return builder;
}

public static ILoggingBuilder AddLogFormatter<TFormatter, TOptions>(this ILoggingBuilder builder)
public static ILoggingBuilder AddConsoleLogFormatter<TFormatter, TOptions>(this ILoggingBuilder builder)
where TOptions : class
where TFormatter : class, ILogFormatter
where TFormatter : class, IConsoleLogFormatter
{
builder.AddConfiguration();

builder.Services.TryAddEnumerable(ServiceDescriptor.Singleton<ILogFormatter, TFormatter>());
builder.Services.TryAddEnumerable(ServiceDescriptor.Singleton<IConsoleLogFormatter, TFormatter>());
builder.Services.AddSingleton<IConfigureOptions<TOptions>, LogFormatterOptionsSetup<TFormatter, TOptions>>();
builder.Services.AddSingleton<IOptionsChangeTokenSource<TOptions>, LoggerProviderOptionsChangeTokenSource<TOptions, TFormatter>>();

Expand All @@ -77,16 +77,16 @@ public static ILoggingBuilder AddLogFormatter<TFormatter, TOptions>(this ILoggin
return builder;
}

public static ILoggingBuilder AddLogFormatter<TFormatter, TOptions>(this ILoggingBuilder builder, Action<TOptions> configure)
public static ILoggingBuilder AddConsoleLogFormatter<TFormatter, TOptions>(this ILoggingBuilder builder, Action<TOptions> configure)
where TOptions : class
where TFormatter : class, ILogFormatter
where TFormatter : class, IConsoleLogFormatter
{
if (configure == null)
{
throw new ArgumentNullException(nameof(configure));
}

builder.AddLogFormatter<TFormatter, TOptions>();
builder.AddConsoleLogFormatter<TFormatter, TOptions>();

builder.Services.Configure(configure);

Expand All @@ -96,7 +96,7 @@ public static ILoggingBuilder AddLogFormatter<TFormatter, TOptions>(this ILoggin

internal class LogFormatterOptionsSetup<TFormatter, TOptions> : ConfigureFromConfigurationOptions<TOptions>
where TOptions : class
where TFormatter : class, ILogFormatter
where TFormatter : class, IConsoleLogFormatter
{
public LogFormatterOptionsSetup(ILoggerProviderConfiguration<TFormatter> providerConfiguration)
: base(providerConfiguration.Configuration)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class ConsoleLoggerProvider : ILoggerProvider, ISupportExternalScope
{
private readonly IOptionsMonitor<ConsoleLoggerOptions> _options;
private readonly ConcurrentDictionary<string, ConsoleLogger> _loggers;
private readonly ConcurrentDictionary<string, ILogFormatter> _formatters;
private readonly ConcurrentDictionary<string, IConsoleLogFormatter> _formatters;
private readonly ConsoleLoggerProcessor _messageQueue;

private IDisposable _optionsReloadToken;
Expand All @@ -30,11 +30,11 @@ public class ConsoleLoggerProvider : ILoggerProvider, ISupportExternalScope
/// </summary>
/// <param name="options">The options to create <see cref="ConsoleLogger"/> instances with.</param>
/// <param name="formatters"></param>
public ConsoleLoggerProvider(IOptionsMonitor<ConsoleLoggerOptions> options, IEnumerable<ILogFormatter> formatters)
public ConsoleLoggerProvider(IOptionsMonitor<ConsoleLoggerOptions> options, IEnumerable<IConsoleLogFormatter> formatters)
{
_options = options;
_loggers = new ConcurrentDictionary<string, ConsoleLogger>();
_formatters = new ConcurrentDictionary<string, ILogFormatter>(formatters.ToDictionary(f => f.Name));
_formatters = new ConcurrentDictionary<string, IConsoleLogFormatter>(formatters.ToDictionary(f => f.Name));

ReloadLoggerOptions(options.CurrentValue);
_optionsReloadToken = _options.OnChange(ReloadLoggerOptions);
Expand All @@ -56,7 +56,7 @@ public ConsoleLoggerProvider(IOptionsMonitor<ConsoleLoggerOptions> options, IEnu
private void ReloadLoggerOptions(ConsoleLoggerOptions options)
{
string nameFromFormat = Enum.GetName(typeof(ConsoleLoggerFormat), options?.Format);
_formatters.TryGetValue(options?.Formatter ?? nameFromFormat, out ILogFormatter logFormatter);
_formatters.TryGetValue(options?.Formatter ?? nameFromFormat, out IConsoleLogFormatter logFormatter);
if (logFormatter == null)
{
logFormatter = _formatters[nameFromFormat];
Expand All @@ -72,7 +72,7 @@ private void ReloadLoggerOptions(ConsoleLoggerOptions options)
public ILogger CreateLogger(string name)
{
string nameFromFormat = Enum.GetName(typeof(ConsoleLoggerFormat), _options.CurrentValue.Format);
_formatters.TryGetValue(_options.CurrentValue.Formatter ?? nameFromFormat, out ILogFormatter logFormatter);
_formatters.TryGetValue(_options.CurrentValue.Formatter ?? nameFromFormat, out IConsoleLogFormatter logFormatter);
if (logFormatter == null)
{
logFormatter = _formatters[nameFromFormat];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace Microsoft.Extensions.Logging.Console
{
internal class CompactLogFormatter : ILogFormatter, IDisposable
internal class CompactLogFormatter : IConsoleLogFormatter, IDisposable
{
private IDisposable _optionsReloadToken;
private static readonly string _loglevelPadding = ": ";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

namespace Microsoft.Extensions.Logging.Console
{
public class DefaultLogFormatter : ILogFormatter, IDisposable
public class DefaultConsoleLogFormatter : IConsoleLogFormatter, IDisposable
{
private static readonly string _loglevelPadding = ": ";
private static readonly string _messagePadding;
Expand All @@ -22,21 +22,21 @@ public class DefaultLogFormatter : ILogFormatter, IDisposable
[ThreadStatic]
private static StringBuilder _logBuilder;

static DefaultLogFormatter()
static DefaultConsoleLogFormatter()
{
var logLevelString = GetLogLevelString(LogLevel.Information);
_messagePadding = new string(' ', logLevelString.Length + _loglevelPadding.Length);
_newLineWithMessagePadding = Environment.NewLine + _messagePadding;
}

public DefaultLogFormatter(IOptionsMonitor<DefaultLogFormatterOptions> options)
public DefaultConsoleLogFormatter(IOptionsMonitor<DefaultConsoleLogFormatterOptions> options)
{
FormatterOptions = options.CurrentValue;
ReloadLoggerOptions(options.CurrentValue);
_optionsReloadToken = options.OnChange(ReloadLoggerOptions);
}

private void ReloadLoggerOptions(DefaultLogFormatterOptions options)
private void ReloadLoggerOptions(DefaultConsoleLogFormatterOptions options)
{
FormatterOptions = options;
}
Expand All @@ -48,7 +48,7 @@ public void Dispose()

public string Name => "Default";

public DefaultLogFormatterOptions FormatterOptions { get; set; }
public DefaultConsoleLogFormatterOptions FormatterOptions { get; set; }

public LogMessageEntry Format<TState>(LogLevel logLevel, string logName, int eventId, TState state, Exception exception, Func<TState, Exception, string> formatter, IExternalScopeProvider scopeProvider)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@

namespace Microsoft.Extensions.Logging.Console
{
public class DefaultLogFormatterOptions
public class DefaultConsoleLogFormatterOptions
{
public DefaultLogFormatterOptions() { }
public DefaultConsoleLogFormatterOptions() { }

/// <summary>
/// Includes scopes when <see langword="true" />.
Expand Down
Loading