-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b06b0eb
commit 63b68ce
Showing
3 changed files
with
40 additions
and
37 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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 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); | ||
} | ||
} |
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