-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #259 from nenoNaninu/f/console_formatter
change console formatter
- Loading branch information
Showing
4 changed files
with
47 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
src/TypedSignalR.Client.TypeScript.Generator/Logging/SimpleConsoleAppFormatter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters