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
FormatterNames const not instance properties
  • Loading branch information
maryamariyan committed May 15, 2020
commit 0499b0a065338d2f3a36827dcd9abe55c5c6e2bf
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