diff --git a/Directory.Packages.props b/Directory.Packages.props index 33ff25a..572cab1 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -11,7 +11,10 @@ - + + + + diff --git a/src/TypedSignalR.Client.TypeScript.Generator/Logging/SimpleConsoleAppFormatter.cs b/src/TypedSignalR.Client.TypeScript.Generator/Logging/SimpleConsoleAppFormatter.cs new file mode 100644 index 0000000..59a0cbb --- /dev/null +++ b/src/TypedSignalR.Client.TypeScript.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 TypedSignalR.Client.TypeScript.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/TypedSignalR.Client.TypeScript.Generator/Program.cs b/src/TypedSignalR.Client.TypeScript.Generator/Program.cs index 5d149b0..55ffb82 100644 --- a/src/TypedSignalR.Client.TypeScript.Generator/Program.cs +++ b/src/TypedSignalR.Client.TypeScript.Generator/Program.cs @@ -1,16 +1,13 @@ using Cocona; using Microsoft.Build.Locator; -using Microsoft.Extensions.Logging; using TypedSignalR.Client.TypeScript; +using TypedSignalR.Client.TypeScript.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/TypedSignalR.Client.TypeScript.Generator/TypedSignalR.Client.TypeScript.Generator.csproj b/src/TypedSignalR.Client.TypeScript.Generator/TypedSignalR.Client.TypeScript.Generator.csproj index 6d5d7d5..a280835 100644 --- a/src/TypedSignalR.Client.TypeScript.Generator/TypedSignalR.Client.TypeScript.Generator.csproj +++ b/src/TypedSignalR.Client.TypeScript.Generator/TypedSignalR.Client.TypeScript.Generator.csproj @@ -27,6 +27,9 @@ + + +