All the examples I can find about using Serilog in an ASP .NET Core Web Application use Microsoft's ILogger<T> interface instead of using Serilog's ILogger interface.
How do I make it so that Serilog's ILogger can be injected via constructor, instead?
using Serilog;
public class HomeController : Controller
{
ILogger logger;
public HomeController(ILogger logger)
{
this.logger = logger;
}
public IActionResult Index()
{
this.logger.Information("Index was called");
return View();
}
}
Serilog ASP.NET Corethe first result is the Serilog ASP.NET Core package that does just thatLogclass to avoid polluting constructors with irrelevant details); we hook up Serilog to MEL, but only third-party components/the framework use it, so we never see the MEL interfaces. Works nicely for us.