diff --git a/Directory.Packages.props b/Directory.Packages.props index 77170d1..fcd7af1 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -11,7 +11,10 @@ + + + diff --git a/src/Tapper.Generator/Logging/SimpleConsoleAppFormatter.cs b/src/Tapper.Generator/Logging/SimpleConsoleAppFormatter.cs new file mode 100644 index 0000000..e031ba1 --- /dev/null +++ b/src/Tapper.Generator/Logging/SimpleConsoleAppFormatter.cs @@ -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(); + + return builder; + } +} + +internal class SimpleConsoleAppFormatter : ConsoleFormatter +{ + public const string FormatterName = "SimpleConsoleApp"; + + public SimpleConsoleAppFormatter() : base(FormatterName) + { + } + + public override void Write(in LogEntry logEntry, IExternalScopeProvider? scopeProvider, TextWriter textWriter) + { + string message = logEntry.Formatter(logEntry.State, logEntry.Exception); + + if (message is null) + { + return; + } + + textWriter.WriteLine(message); + } +} diff --git a/src/Tapper.Generator/Program.cs b/src/Tapper.Generator/Program.cs index 21d87bc..c778442 100644 --- a/src/Tapper.Generator/Program.cs +++ b/src/Tapper.Generator/Program.cs @@ -1,16 +1,13 @@ using Cocona; using Microsoft.Build.Locator; -using Microsoft.Extensions.Logging; using Tapper; +using Tapper.Logging; MSBuildLocator.RegisterDefaults(); var builder = CoconaApp.CreateBuilder(); -builder.Logging.AddSimpleConsole(options => -{ - options.SingleLine = true; -}); +builder.Logging.AddSimpleConsoleApp(); var app = builder.Build(); diff --git a/src/Tapper.Generator/Tapper.Generator.csproj b/src/Tapper.Generator/Tapper.Generator.csproj index 0d344fb..50df083 100644 --- a/src/Tapper.Generator/Tapper.Generator.csproj +++ b/src/Tapper.Generator/Tapper.Generator.csproj @@ -28,6 +28,9 @@ + + +