I would like to use the .NET Core Logger in an ExceptionFilter like this:
public class GlobalExceptionAttribute : ExceptionFilterAttribute
{
private readonly ILogger<Inspection> _logger;
public GlobalExceptionAttribute(ILogger<Inspection> logger)
{
_logger = logger;
}
public override void OnException(ExceptionContext context)
{
_logger.LogError("Error");
}
...
}
But in my Controller this leads to an error message, that tells me I need to provide a logger as a parameter:
[GlobalException]
public class Inspection : Controller
{
...
I actually want the logger to be injected automatically by .NET Cores DI. How can I archive that?