alefranz / MELT

MELT is a free, open source, testing library for the .NET Standard Microsoft Extensions Logging library. It is a solution to easily test logs.
Apache License 2.0
74 stars 5 forks source link

Create an ILogger<> directly #28

Open lostincomputer opened 3 years ago

lostincomputer commented 3 years ago

This is a feature request.

Most of my code and probably everyone else's code only depends on ILogger<> such as this:

class MyController(ILogger<MyController> logger)

In order to test this code I need to do this:

var loggerFactory = TestLoggerFactory.Create();
new MyController(loggerFactory.CreateLogger<MyController>());
// Assert loggerFactory.Sink here

I think that I would be great if there is a shorthand for directly creating an ILogger since most code under test only depends on ILogger<>.

var logger = TestLogger.Create<MyController>();
new MyController(logger);
// Assert logger.Sink here

This makes the test code shorter.

Edit: And thanks for making the library.

alefranz commented 3 years ago

Hello, it is a valid point and I will have a look at it.

Thanks for the feedback.