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 default to colored
  • Loading branch information
maryamariyan committed May 26, 2020
commit 8baee3dcc90672bd011199a6641a967573a1b09b
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,22 @@ public static partial class ConsoleLoggerExtensions
public static Microsoft.Extensions.Logging.ILoggingBuilder AddConsole(this Microsoft.Extensions.Logging.ILoggingBuilder builder, string formatterName) { 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; }
public static Microsoft.Extensions.Logging.ILoggingBuilder UseDefaultConsoleLogFormatter(this Microsoft.Extensions.Logging.ILoggingBuilder builder, System.Action<Microsoft.Extensions.Logging.Console.DefaultConsoleLogFormatterOptions> configure) { throw null; }
public static Microsoft.Extensions.Logging.ILoggingBuilder UseColoredConsoleLogFormatter(this Microsoft.Extensions.Logging.ILoggingBuilder builder, System.Action<Microsoft.Extensions.Logging.Console.ColoredConsoleLogFormatterOptions> configure) { throw null; }
public static Microsoft.Extensions.Logging.ILoggingBuilder UseJsonConsoleLogFormatter(this Microsoft.Extensions.Logging.ILoggingBuilder builder, System.Action<Microsoft.Extensions.Logging.Console.JsonConsoleLogFormatterOptions> configure) { throw null; }
public static Microsoft.Extensions.Logging.ILoggingBuilder UseSystemdConsoleLogFormatter(this Microsoft.Extensions.Logging.ILoggingBuilder builder, System.Action<Microsoft.Extensions.Logging.Console.SystemdConsoleLogFormatterOptions> configure) { throw null; }
}
}
namespace Microsoft.Extensions.Logging.Console
{
public partial class ColoredConsoleLogFormatterOptions : Microsoft.Extensions.Logging.Console.SystemdConsoleLogFormatterOptions
{
public ColoredConsoleLogFormatterOptions() { }
public bool DisableColors { get { throw null; } set { } }
public bool MultiLine { get { throw null; } set { } }
}
public static partial class ConsoleLogFormatterNames
{
public const string Default = "default";
public const string Colored = "colored";
public const string Json = "json";
public const string Systemd = "systemd";
}
Expand All @@ -35,7 +41,7 @@ public enum ConsoleLoggerFormat
public partial class ConsoleLoggerOptions
{
public ConsoleLoggerOptions() { }
[System.ObsoleteAttribute("ConsoleLoggerOptions.DisableColors has been deprecated. Please use DefaultConsoleLogFormatterOptions.DisableColors instead.", false)]
[System.ObsoleteAttribute("ConsoleLoggerOptions.DisableColors has been deprecated. Please use ColoredConsoleLogFormatterOptions.DisableColors instead.", false)]
public bool DisableColors { get { throw null; } set { } }
[System.ObsoleteAttribute("ConsoleLoggerOptions.Format has been deprecated. Please use ConsoleLoggerOptions.FormatterName instead.", false)]
public Microsoft.Extensions.Logging.Console.ConsoleLoggerFormat Format { get { throw null; } set { } }
Expand Down Expand Up @@ -66,12 +72,6 @@ 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 DefaultConsoleLogFormatterOptions : Microsoft.Extensions.Logging.Console.SystemdConsoleLogFormatterOptions
{
public DefaultConsoleLogFormatterOptions() { }
public bool DisableColors { get { throw null; } set { } }
public bool MultiLine { get { throw null; } set { } }
}
public partial interface IConsoleLogFormatter
{
string Name { get; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public static ILoggingBuilder AddConsole(this ILoggingBuilder builder)

builder.AddConsoleLogFormatter<JsonConsoleLogFormatter, JsonConsoleLogFormatterOptions>();
builder.AddConsoleLogFormatter<SystemdConsoleLogFormatter, SystemdConsoleLogFormatterOptions>();
builder.AddConsoleLogFormatter<DefaultConsoleLogFormatter, DefaultConsoleLogFormatterOptions>();
builder.AddConsoleLogFormatter<ColoredConsoleLogFormatter, ColoredConsoleLogFormatterOptions>();

builder.Services.TryAddEnumerable(ServiceDescriptor.Singleton<ILoggerProvider, ConsoleLoggerProvider>());
LoggerProviderOptions.RegisterProviderOptions<ConsoleLoggerOptions, ConsoleLoggerProvider>(builder.Services);
Expand Down Expand Up @@ -73,7 +73,7 @@ public static ILoggingBuilder AddConsole(this ILoggingBuilder builder, string fo
return builder.AddConsole(configure);
}

public static ILoggingBuilder UseDefaultConsoleLogFormatter(this ILoggingBuilder builder, Action<DefaultConsoleLogFormatterOptions> configure)
public static ILoggingBuilder UseColoredConsoleLogFormatter(this ILoggingBuilder builder, Action<ColoredConsoleLogFormatterOptions> configure)
{
if (configure == null)
{
Expand All @@ -83,7 +83,7 @@ public static ILoggingBuilder UseDefaultConsoleLogFormatter(this ILoggingBuilder
builder.AddConsole();
builder.Services.Configure(configure);

Action<ConsoleLoggerOptions> configureFormatter = (options) => { options.FormatterName = ConsoleLogFormatterNames.Default; };
Action<ConsoleLoggerOptions> configureFormatter = (options) => { options.FormatterName = ConsoleLogFormatterNames.Colored; };
builder.Services.Configure(configureFormatter);

return builder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace Microsoft.Extensions.Logging.Console
/// </summary>
public class ConsoleLoggerOptions
{
[System.ObsoleteAttribute("ConsoleLoggerOptions.DisableColors has been deprecated. Please use DefaultConsoleLogFormatterOptions.DisableColors instead.", false)]
[System.ObsoleteAttribute("ConsoleLoggerOptions.DisableColors has been deprecated. Please use ColoredConsoleLogFormatterOptions.DisableColors instead.", false)]
public bool DisableColors { get; set; }

/// <summary>
Expand All @@ -35,7 +35,7 @@ public ConsoleLoggerFormat Format
}
else
{
FormatterName = ConsoleLogFormatterNames.Default;
FormatterName = ConsoleLogFormatterNames.Colored;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ private void ReloadLoggerOptions(ConsoleLoggerOptions options)
//}
if (logFormatter == null)
{
logFormatter = _formatters[ConsoleLogFormatterNames.Default];
logFormatter = _formatters[ConsoleLogFormatterNames.Colored];
}

foreach (var logger in _loggers)
Expand All @@ -89,7 +89,7 @@ private void UpdateFormatterOptions(IConsoleLogFormatter formatter, ConsoleLogge
if (deprecatedFromOptions.FormatterName != null)
return;
// kept for deprecated apis:
if (formatter is DefaultConsoleLogFormatter defaultFormatter)
if (formatter is ColoredConsoleLogFormatter defaultFormatter)
{
defaultFormatter.FormatterOptions.DisableColors = deprecatedFromOptions.DisableColors;
defaultFormatter.FormatterOptions.IncludeScopes = deprecatedFromOptions.IncludeScopes;
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 DefaultConsoleLogFormatter : IConsoleLogFormatter, IDisposable
internal class ColoredConsoleLogFormatter : IConsoleLogFormatter, IDisposable
{
private static readonly string _loglevelPadding = ": ";
private static readonly string _messagePadding;
Expand All @@ -24,21 +24,21 @@ internal class DefaultConsoleLogFormatter : IConsoleLogFormatter, IDisposable
[ThreadStatic]
private static StringBuilder _logBuilder;

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

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

private void ReloadLoggerOptions(DefaultConsoleLogFormatterOptions options)
private void ReloadLoggerOptions(ColoredConsoleLogFormatterOptions options)
{
FormatterOptions = options;
}
Expand All @@ -48,9 +48,9 @@ public void Dispose()
_optionsReloadToken?.Dispose();
}

public string Name => ConsoleLogFormatterNames.Default;
public string Name => ConsoleLogFormatterNames.Colored;

internal DefaultConsoleLogFormatterOptions FormatterOptions { get; set; }
internal ColoredConsoleLogFormatterOptions 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 DefaultConsoleLogFormatterOptions : SystemdConsoleLogFormatterOptions
public class ColoredConsoleLogFormatterOptions : SystemdConsoleLogFormatterOptions
{
public DefaultConsoleLogFormatterOptions() { }
public ColoredConsoleLogFormatterOptions() { }

/// <summary>
/// Disables colors when <see langword="true" />.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Microsoft.Extensions.Logging.Console
{
public static class ConsoleLogFormatterNames
{
public const string Default = "default";
public const string Colored = "colored";
public const string Json = "json";
public const string Systemd = "systemd";
}
Expand Down