Skip to content

Refactored to support exception handling and less allocations#3

Open
OlegGavrilov wants to merge 1 commit into
agc93:mainfrom
OlegGavrilov:main
Open

Refactored to support exception handling and less allocations#3
OlegGavrilov wants to merge 1 commit into
agc93:mainfrom
OlegGavrilov:main

Conversation

@OlegGavrilov

Copy link
Copy Markdown

Hello! Hope it could be merged or maybe give some inspiration. Thanks!

@agc93

agc93 commented Jan 6, 2021

Copy link
Copy Markdown
Owner

Hey, thanks so much for the contribution!

I'm out of town right now, but I'll try and have a look over the changes here in the next week or so 👍

@agc93 agc93 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Thanks again for the contribution. There's a lot of changes there and before I get too deep into it, I just want to ask:

Are you seeing any performance implications with the current implementation? I can see that a lot of the changes seem to be basically just to reduce the number of allocations so I want to know if the allocations are causing a problem you're facing or if it's optimising pre-emptively?

public static class SpectreConsoleLoggingExtensions
{
public static ILoggingBuilder AddSpectreConsole(this ILoggingBuilder loggingBuilder, SpectreConsoleLoggerConfiguration config = null)
private static ILoggingBuilder AddSpectreConsole(this ILoggingBuilder loggingBuilder, SpectreConsoleLoggerConfiguration config = null)

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Why make this private? That prevents consuming applications from using the extension method.

}

public static ILoggingBuilder AddInlineSpectreConsole(this ILoggingBuilder loggingBuilder, SpectreConsoleLoggerConfiguration config = null) {
private static ILoggingBuilder AddInlineSpectreConsole(this ILoggingBuilder loggingBuilder, SpectreConsoleLoggerConfiguration config = null) {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Same as above, this prevents consuming apps from calling the extension.

Comment on lines +46 to 66
private const string Unknown = "[italic dim grey]unkn[/]: ";
private const string Trace = "[italic dim grey]trce[/]: ";
private const string Debug = "[dim grey]dbug[/]: ";
private const string Information = "[dim deepskyblue2]info[/]: ";
private const string Warning = "[bold orange3]warn[/]: ";
private const string Error = "[bold red]fail[/]: ";
private const string Critical = "[bold underline red on white]crit[/]: ";

private static string GetLevelMarkup(LogLevel level)
{
return level switch
{
LogLevel.Trace => "[italic dim grey]trce[/]: ",
LogLevel.Debug => "[dim grey]dbug[/]: ",
LogLevel.Information => "[dim deepskyblue2]info[/]: ",
LogLevel.Warning => "[bold orange3]warn[/]: ",
LogLevel.Error => "[bold red]fail[/]: ",
LogLevel.Critical => "[bold underline red on white]crit[/]: ",
_ => throw new ArgumentOutOfRangeException(nameof(level))
LogLevel.Trace => Trace,
LogLevel.Debug => Debug,
LogLevel.Information => Information,
LogLevel.Warning => Warning,
LogLevel.Error => Error,
LogLevel.Critical => Critical,
_ => Unknown
};
}

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Just so I know, is this change intended to solve an actual problem you're facing?

I get that it's probably slightly more performant but it's also (in my view) dramatically less readable, so I'm not sure if you're actually seeing an issue here or if you're just trying to preemptively optimise?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants