Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
d4019c3
structured logger formatter prototype
maryamariyan Apr 15, 2020
e62739b
add ref to Linq + add public apis
maryamariyan Apr 15, 2020
ae48df1
New APIs for Structured Log Formatting
maryamariyan May 12, 2020
968496c
Apply review feedback
maryamariyan May 14, 2020
55ea183
nit cleanup
maryamariyan May 14, 2020
d2e0808
- messages can color vars in messages (Compact)
maryamariyan May 15, 2020
cf38d82
TODO
maryamariyan May 15, 2020
515bde6
Rename to XConsoleLog...
maryamariyan May 15, 2020
6b5de1e
FormatterNames const not instance properties
maryamariyan May 15, 2020
c9d0939
add AddCompact and other helpers
maryamariyan May 15, 2020
27ddec2
Rename AddCompactFormatter for short?
maryamariyan May 15, 2020
a558275
Revert "Rename AddCompactFormatter for short?"
maryamariyan May 21, 2020
f58aa1f
Add back deprecated APIs
maryamariyan May 21, 2020
94e5c18
exception messaging in compact remains single line
maryamariyan May 21, 2020
9c3345e
cleanup
maryamariyan May 26, 2020
e441d04
rename default to colored
maryamariyan May 26, 2020
3cc92ed
deprecate ConsoleLoggerFormat
maryamariyan May 26, 2020
d72c6f9
minor rename
maryamariyan May 26, 2020
b7085b5
Rename back to default formatter
maryamariyan May 27, 2020
12223c4
triple slash comments on new helpers
maryamariyan May 28, 2020
af1bc5c
slight impl fixup
maryamariyan May 28, 2020
6ab5aa9
ConsoleLoggerProvider: keep ctor not deprecate
maryamariyan May 28, 2020
85d50b2
Added triple slash comments
maryamariyan May 28, 2020
ff39ae1
corner cases
maryamariyan May 29, 2020
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
cleanup
  • Loading branch information
maryamariyan committed May 29, 2020
commit 9c3345e1dc22af80b0e88ef752a3f563307f1376
Original file line number Diff line number Diff line change
Expand Up @@ -14,33 +14,18 @@ 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 UseCompactConsoleLogFormatter(this Microsoft.Extensions.Logging.ILoggingBuilder builder, System.Action<Microsoft.Extensions.Logging.Console.ColoredConsoleLogFormatterOptions> configure) { throw null; }
public static Microsoft.Extensions.Logging.ILoggingBuilder UseDefaultConsoleLogFormatter(this Microsoft.Extensions.Logging.ILoggingBuilder builder, System.Action<Microsoft.Extensions.Logging.Console.ColoredConsoleLogFormatterOptions> configure) { 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 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.BasicConsoleLogFormatterOptions> 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 BasicConsoleLogFormatterOptions
{
public BasicConsoleLogFormatterOptions() { }
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 class ColoredConsoleLogFormatterOptions : Microsoft.Extensions.Logging.Console.BasicConsoleLogFormatterOptions
{
public ColoredConsoleLogFormatterOptions() { }
public bool DisableColors { get { throw null; } set { } }
}
public static partial class ConsoleLogFormatterNames
{
public const string Compact = "Compact";
public const string Default = "Default";
public const string Json = "Json";
public const string Systemd = "Systemd";
public const string Default = "default";
public const string Json = "json";
public const string Systemd = "systemd";
}
public enum ConsoleLoggerFormat
{
Expand Down Expand Up @@ -81,15 +66,20 @@ 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; }
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);
}
public partial class JsonConsoleLogFormatterOptions : Microsoft.Extensions.Logging.Console.BasicConsoleLogFormatterOptions
public partial class JsonConsoleLogFormatterOptions : Microsoft.Extensions.Logging.Console.SystemdConsoleLogFormatterOptions
{
public JsonConsoleLogFormatterOptions() { }
public System.Text.Json.JsonSerializerOptions JsonSerializerOptions { get { throw null; } set { } }
public System.Text.Json.JsonWriterOptions JsonWriterOptions { get { throw null; } set { } }
}
public readonly partial struct LogMessageEntry
Expand All @@ -98,4 +88,12 @@ 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 SystemdConsoleLogFormatterOptions
{
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 { } }
public bool UseUtcTimestamp { get { throw null; } set { } }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,8 @@ public static ILoggingBuilder AddConsole(this ILoggingBuilder builder)
builder.AddConfiguration();

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

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

public static ILoggingBuilder UseCompactConsoleLogFormatter(this ILoggingBuilder builder, Action<ColoredConsoleLogFormatterOptions> configure)
{
if (configure == null)
{
throw new ArgumentNullException(nameof(configure));
}

builder.AddConsole();
builder.Services.Configure(configure);

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

return builder;
}

public static ILoggingBuilder UseDefaultConsoleLogFormatter(this ILoggingBuilder builder, Action<ColoredConsoleLogFormatterOptions> configure)
public static ILoggingBuilder UseDefaultConsoleLogFormatter(this ILoggingBuilder builder, Action<DefaultConsoleLogFormatterOptions> configure)
{
if (configure == null)
{
Expand Down Expand Up @@ -122,7 +105,7 @@ public static ILoggingBuilder UseJsonConsoleLogFormatter(this ILoggingBuilder bu
return builder;
}

public static ILoggingBuilder UseSystemdConsoleLogFormatter(this ILoggingBuilder builder, Action<BasicConsoleLogFormatterOptions> configure)
public static ILoggingBuilder UseSystemdConsoleLogFormatter(this ILoggingBuilder builder, Action<SystemdConsoleLogFormatterOptions> configure)
{
if (configure == null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,21 @@ public ConsoleLoggerProvider(IOptionsMonitor<ConsoleLoggerOptions> options, IEnu
// warning: ReloadLoggerOptions can be called before the ctor completed,... before registering all of the state used in this method need to be initialized
private void ReloadLoggerOptions(ConsoleLoggerOptions options)
{
string nameFromFormat = Enum.GetName(typeof(ConsoleLoggerFormat), options?.Format);
_formatters.TryGetValue(options?.FormatterName ?? nameFromFormat, out IConsoleLogFormatter logFormatter);
IConsoleLogFormatter logFormatter = null;
if (options.FormatterName != null)
{
_formatters.TryGetValue(options.FormatterName.ToLower(), out logFormatter);
}
//else
//{
// string nameFromFormat = Enum.GetName(typeof(ConsoleLoggerFormat), options?.Format);
// _formatters.TryGetValue(nameFromFormat, out IConsoleLogFormatter logFormatter);
// UpdateFormatterOptions(logFormatter, options);
//}
if (logFormatter == null)
{
logFormatter = _formatters[nameFromFormat];
logFormatter = _formatters[ConsoleLogFormatterNames.Default];
}
UpdateFormatterOptions(logFormatter, options);

foreach (var logger in _loggers)
{
Expand Down
Loading