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
FormatterNames const not instance properties
  • Loading branch information
maryamariyan committed May 29, 2020
commit 6b5de1e3e9d821645d38447028e9ad8e12756ef2
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ public CompactLogFormatterOptions() { }
public string TimestampFormat { get { throw null; } set { } }
public bool UseUtcTimestamp { 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 enum ConsoleLoggerFormat
{
Default = 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ public static ILoggingBuilder AddConsole(this ILoggingBuilder builder)
builder.AddConfiguration();

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

builder.Services.TryAddEnumerable(ServiceDescriptor.Singleton<ILoggerProvider, ConsoleLoggerProvider>());
LoggerProviderOptions.RegisterProviderOptions<ConsoleLoggerOptions, ConsoleLoggerProvider>(builder.Services);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public void Dispose()

public CompactLogFormatterOptions FormatterOptions { get; set; }

public string Name => "Compact";
public string Name => ConsoleLogFormatterNames.Compact;

public LogMessageEntry Format<TState>(LogLevel logLevel, string logName, int eventId, TState state, Exception exception, Func<TState, Exception, string> formatter, IExternalScopeProvider scopeProvider)
{
Expand Down Expand Up @@ -84,7 +84,7 @@ private LogMessageEntry FormatHelper<TState>(LogLevel logLevel, string logName,
}
if (logLevelString != null)
{
messages.Add(new ConsoleMessage(logLevelString,logLevelColors.Background, logLevelColors.Foreground));
messages.Add(new ConsoleMessage(logLevelString + " ", logLevelColors.Background, logLevelColors.Foreground));
}

messages.Add(new ConsoleMessage($"{logName}[{eventId}] ", null, null));
Expand Down Expand Up @@ -185,6 +185,7 @@ private LogMessageEntry FormatHelper<TState>(LogLevel logLevel, string logName,
messages.Add(new ConsoleMessage(exception.ToString(), null, null));
// TODO: confirm exception message all in one line?
}
messages.Add(new ConsoleMessage(Environment.NewLine, null, null));

return new LogMessageEntry(
messages: messages.ToArray(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

namespace Microsoft.Extensions.Logging.Console
{
public static class ConsoleLogFormatterNames
{
public const string Compact = nameof(Compact);
public const string Default = nameof(Default);
public const string Json = nameof(Json);
public const string Systemd = nameof(Systemd);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public void Dispose()
_optionsReloadToken?.Dispose();
}

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

public DefaultConsoleLogFormatterOptions FormatterOptions { get; set; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public JsonConsoleLogFormatter(IOptionsMonitor<JsonConsoleLogFormatterOptions> o
_optionsReloadToken = options.OnChange(ReloadLoggerOptions);
}

public string Name => "Json";
public string Name => ConsoleLogFormatterNames.Json;

private string WriteJson(LogLevel logLevel, string logName, int eventId, string message, Exception exception, IExternalScopeProvider scopeProvider)//long[] extraData)
{
Expand Down Expand Up @@ -116,7 +116,10 @@ public LogMessageEntry Format(LogLevel logLevel, string logName, int eventId, st
}
_logBuilder = logBuilder;

var messages = new ConsoleMessage[1] { new ConsoleMessage(formattedMessage, null, null) };
var messages = new ConsoleMessage[2] {
new ConsoleMessage(formattedMessage, null, null),
new ConsoleMessage(Environment.NewLine, null, null)
};

return new LogMessageEntry(
messages: messages,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public void Dispose()
_optionsReloadToken?.Dispose();
}

public string Name => "Systemd";
public string Name => ConsoleLogFormatterNames.Systemd;

public SystemdConsoleLogFormatterOptions FormatterOptions { get; set; }

Expand Down