Created a blank ASP.NET Core 2.0 application. In Startup.cs, would like to log incoming requests. So in configure method, I am using Microsoft.Extensions.Logging.ILogger
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILogger logger)
{
app.Use(next =>
{
return async context =>
{
logger.LogInformation("Incoming request");
await next(context);
logger.LogInformation("Outgoing response");
};
});
However, when I build the project, its complaining
An error occurred while starting the application.
InvalidOperationException: No service for type 'Microsoft.Extensions.Logging.ILogger' has been registered.
Why and how should I register this service? Had it been my interface, it would have still made sense to do
services.AddScope
in ConfigureServices