Last active
January 4, 2021 15:17
-
-
Save mikehadlow/597859a199e53f1867f1eefc85aa6442 to your computer and use it in GitHub Desktop.
How to create a ConsoleLoggerProvider without the full hosting framework.
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
using Microsoft.Extensions.Logging.Console; | |
using Microsoft.Extensions.Options; | |
using System; | |
namespace Sample | |
{ | |
class Program | |
{ | |
static void Main() | |
{ | |
var loggerProvider = new ConsoleLoggerProvider(new OptionsMonitor<ConsoleLoggerOptions>(new ConsoleLoggerOptions())); | |
// use the loggerProvider ... | |
} | |
} | |
public class OptionsMonitor<T> : IOptionsMonitor<T> | |
{ | |
private readonly T options; | |
public OptionsMonitor(T options) | |
{ | |
this.options = options; | |
} | |
public T CurrentValue => options; | |
public T Get(string name) => options; | |
public IDisposable OnChange(Action<T, string> listener) => new NullDisposable(); | |
private class NullDisposable : IDisposable | |
{ | |
public void Dispose() { } | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment