Skip to content

Commit

Permalink
add SimpleConsoleAppFormatter
Browse files Browse the repository at this point in the history
  • Loading branch information
nenoNaninu committed Dec 1, 2024
1 parent b06b0eb commit 63b68ce
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 37 deletions.
32 changes: 0 additions & 32 deletions src/Tapper.Generator/CliConsoleFormatter.cs

This file was deleted.

38 changes: 38 additions & 0 deletions src/Tapper.Generator/Logging/SimpleConsoleAppFormatter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using System.IO;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using Microsoft.Extensions.Logging.Console;

namespace Tapper.Logging;

internal static class ConsoleLoggerExtensions
{
public static ILoggingBuilder AddSimpleConsoleApp(this ILoggingBuilder builder)
{
builder.AddConsole(options => options.FormatterName = SimpleConsoleAppFormatter.FormatterName)
.AddConsoleFormatter<SimpleConsoleAppFormatter, ConsoleFormatterOptions>();

return builder;
}
}

internal class SimpleConsoleAppFormatter : ConsoleFormatter
{
public const string FormatterName = "SimpleConsoleApp";

public SimpleConsoleAppFormatter() : base(FormatterName)
{
}

public override void Write<TState>(in LogEntry<TState> logEntry, IExternalScopeProvider? scopeProvider, TextWriter textWriter)
{
string message = logEntry.Formatter(logEntry.State, logEntry.Exception);

if (message is null)
{
return;
}

textWriter.WriteLine(message);
}
}
7 changes: 2 additions & 5 deletions src/Tapper.Generator/Program.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
using Cocona;
using Microsoft.Build.Locator;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Console;
using Tapper;
using Tapper.Logging;

MSBuildLocator.RegisterDefaults();

var builder = CoconaApp.CreateBuilder();

builder.Logging
.AddConsole(options => options.FormatterName = CliConsoleFormatter.FormatterName)
.AddConsoleFormatter<CliConsoleFormatter, ConsoleFormatterOptions>();
builder.Logging.AddSimpleConsoleApp();

var app = builder.Build();

Expand Down

0 comments on commit 63b68ce

Please sign in to comment.