Skip to content

Commit

Permalink
enhanced: change the console theme color.
Browse files Browse the repository at this point in the history
  • Loading branch information
real-zony committed Apr 25, 2022
1 parent 0f84621 commit e900a92
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
28 changes: 28 additions & 0 deletions src/ZonyLrcTools.Cli/Infrastructure/Logging/CustomConsoleTheme.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System.Collections.Generic;
using Serilog.Sinks.SystemConsole.Themes;

namespace ZonyLrcTools.Cli.Infrastructure.Logging;

public static class CustomConsoleTheme
{
public static AnsiConsoleTheme Code { get; } = new AnsiConsoleTheme(
new Dictionary<ConsoleThemeStyle, string>
{
[ConsoleThemeStyle.Text] = "\x1b[38;5;0253m",
[ConsoleThemeStyle.SecondaryText] = "\x1b[38;5;0246m",
[ConsoleThemeStyle.TertiaryText] = "\x1b[38;5;0242m",
[ConsoleThemeStyle.Invalid] = "\x1b[33;1m",
[ConsoleThemeStyle.Null] = "\x1b[38;5;0038m",
[ConsoleThemeStyle.Name] = "\x1b[38;5;0081m",
[ConsoleThemeStyle.String] = "\x1b[38;5;0216m",
[ConsoleThemeStyle.Number] = "\x1b[38;5;151m",
[ConsoleThemeStyle.Boolean] = "\x1b[38;5;0038m",
[ConsoleThemeStyle.Scalar] = "\x1b[38;5;0079m",
[ConsoleThemeStyle.LevelVerbose] = "\x1b[37m",
[ConsoleThemeStyle.LevelDebug] = "\x1b[37m",
[ConsoleThemeStyle.LevelInformation] = "\x1b[32m\x1b[48;5;0238m",
[ConsoleThemeStyle.LevelWarning] = "\x1b[38;5;0229m",
[ConsoleThemeStyle.LevelError] = "\x1b[38;5;0197m\x1b[48;5;0238m",
[ConsoleThemeStyle.LevelFatal] = "\x1b[38;5;0197m\x1b[48;5;0238m",
});
}
4 changes: 3 additions & 1 deletion src/ZonyLrcTools.Cli/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
using Microsoft.Extensions.Hosting;
using Serilog;
using Serilog.Events;
using Serilog.Sinks.SystemConsole.Themes;
using ZonyLrcTools.Cli.Commands;
using ZonyLrcTools.Cli.Commands.SubCommand;
using ZonyLrcTools.Cli.Infrastructure.DependencyInject;
using ZonyLrcTools.Cli.Infrastructure.Exceptions;
using ZonyLrcTools.Cli.Infrastructure.Logging;

namespace ZonyLrcTools.Cli
{
Expand Down Expand Up @@ -53,7 +55,7 @@ private static void ConfigureLogger()
.MinimumLevel.Override("Microsoft", LogEventLevel.Information)
.MinimumLevel.Override("System.Net.Http.HttpClient", LogEventLevel.Error)
.Enrich.FromLogContext()
.WriteTo.Async(c => c.Console())
.WriteTo.Async(c => c.Console(theme: CustomConsoleTheme.Code))
.WriteTo.Logger(lc =>
{
lc.Filter.ByIncludingOnly(lc => lc.Level == LogEventLevel.Warning)
Expand Down

0 comments on commit e900a92

Please sign in to comment.