-
Notifications
You must be signed in to change notification settings - Fork 191
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use the regular ILogger abstraction in MIDI detection
This should be what we use everywhere else too, but one step at a time
- Loading branch information
Showing
22 changed files
with
195 additions
and
83 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
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,53 @@ | ||
// Copyright 2020 Jon Skeet. All rights reserved. | ||
// Use of this source code is governed by the Apache License 2.0, | ||
// as found in the LICENSE.txt file. | ||
|
||
using Microsoft.Extensions.Logging; | ||
using System; | ||
using System.CommandLine.IO; | ||
|
||
namespace VDrumExplorer.Console | ||
{ | ||
internal sealed class ConsoleLogger : ILogger | ||
{ | ||
private readonly IStandardStreamWriter writer; | ||
|
||
internal ConsoleLogger(IStandardStreamWriter writer) => | ||
this.writer = writer; | ||
|
||
public IDisposable BeginScope<TState>(TState state) => NoOpDisposable.Instance; | ||
|
||
public bool IsEnabled(LogLevel logLevel) => true; | ||
|
||
private void Log(string text) => | ||
writer.WriteLine(text); | ||
|
||
private void Log(string message, Exception e) | ||
{ | ||
// TODO: Aggregate exception etc. | ||
Log($"{message}: {e}"); | ||
} | ||
|
||
public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func<TState, Exception, string> formatter) | ||
{ | ||
var message = formatter(state, exception); | ||
if (exception is null) | ||
{ | ||
Log(message); | ||
} | ||
else | ||
{ | ||
Log(message, exception); | ||
} | ||
} | ||
|
||
private class NoOpDisposable : IDisposable | ||
{ | ||
internal static NoOpDisposable Instance { get; } = new NoOpDisposable(); | ||
|
||
public void Dispose() | ||
{ | ||
} | ||
} | ||
} | ||
} |
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
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
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
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
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
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
Oops, something went wrong.