Skip to content

Commit

Permalink
Merge pull request #259 from nenoNaninu/f/console_formatter
Browse files Browse the repository at this point in the history
change console formatter
  • Loading branch information
nenoNaninu authored Dec 1, 2024
2 parents 09ab689 + 09e8556 commit 9c24230
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 6 deletions.
5 changes: 4 additions & 1 deletion Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.8.0" />
<PackageVersion Include="Microsoft.CodeAnalysis.Workspaces.MSBuild" Version="4.8.0" />
<PackageVersion Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.4" />
<PackageVersion Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.2" />
<PackageVersion Include="Microsoft.Extensions.DependencyInjection" Version="9.0.0" />
<PackageVersion Include="Microsoft.Extensions.Logging" Version="9.0.0" />
<PackageVersion Include="Microsoft.Extensions.Logging.Abstractions" Version="9.0.0" />
<PackageVersion Include="Microsoft.Extensions.Hosting" Version="9.0.0" />
<PackageVersion Include="Microsoft.AspNetCore.SignalR.Client" Version="8.0.10" />
<PackageVersion Include="Microsoft.AspNetCore.SignalR.Protocols.MessagePack" Version="8.0.10" />
<PackageVersion Include="Microsoft.AspNetCore.SignalR.Protocols.Json" Version="8.0.10" />
Expand Down
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 TypedSignalR.Client.TypeScript.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/TypedSignalR.Client.TypeScript.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 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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
<PackageReference Include="Microsoft.Build.Locator" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" />
<PackageReference Include="Microsoft.CodeAnalysis.Workspaces.MSBuild" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" />
<PackageReference Include="Microsoft.Extensions.Logging" />
<PackageReference Include="Microsoft.Extensions.Hosting" />
</ItemGroup>

<ItemGroup>
Expand Down

0 comments on commit 9c24230

Please sign in to comment.