Open alvipeo opened 4 years ago
I kind of found it but I want to extend it.
Here's the NunitLogger I want to use:
public class NunitLogger<T> : ILogger<T>, IDisposable
{
public NunitLogger()
{
}
public void Dispose()
{
}
public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception,
Func<TState, Exception, string> formatter)
{
TestContext.Out.WriteLine(state.ToString());
}
public bool IsEnabled(LogLevel logLevel)
{
return true;
}
public IDisposable BeginScope<TState>(TState state)
{
return this;
}
}
public class NunitLogger : ILogger, IDisposable
{
public NunitLogger()
{
}
public void Dispose()
{
}
public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception,
Func<TState, Exception, string> formatter)
{
TestContext.Out.WriteLine(state.ToString());
}
public bool IsEnabled(LogLevel logLevel)
{
return true;
}
public IDisposable BeginScope<TState>(TState state)
{
return this;
}
}
And now I need to make AddNunitLogging()
extension method.
I"ve had luck with services.AddLogging();
Assuming I have this code:
How can I add ILogger here? Otherwise any command/query that require logger will fail.
Thank you.