net core project. I am using azure application insights to log. I have added below line in services.AddApplicationInsightsTelemetry(); in my startup.cs. In controller and business layer I will get ILogger through dependency injection. But I cam up with something different. I have created ApiExceptionFilter and code looks like below.

```
public class ApiExceptionFilter : ExceptionFilterAttribute
    {  
        public override void OnException(ExceptionContext context)
        {
            ApiError apiError = null;
            if (context.Exception is ApiException)
            {
                // handle explicit 'known' API errors
                var ex = context.Exception as ApiException;
                context.Exception = null;
                apiError = new ApiError(ex.Message);

                context.HttpContext.Response.StatusCode = ex.StatusCode;
            }
            else if (context.Exception is UnauthorizedAccessException)
            {
                apiError = new ApiError("Unauthorized Access");
                context.HttpContext.Response.StatusCode = 401;

                // handle logging here
            }
            else if (context.Exception is NotImplementedException)
            {
                apiError = new ApiError("Not Implemented");
                context.HttpContext.Response.StatusCode = 401;

                // handle logging here
            }
            else if (context.Exception is ArgumentNullException)
            {
                apiError = new ApiError(string.Format("Parameter: {0} is required, it cannot be empty", (context.Exception as ArgumentNullException).ParamName));
                context.HttpContext.Response.StatusCode = 401;

                // handle logging here
            }
            else
            {
                // Unhandled errors
                var msg = context.Exception.GetBaseException().Message;
                string stack = context.Exception.StackTrace;
                apiError = new ApiError(msg);
                apiError.detail = stack;

                context.HttpContext.Response.StatusCode = 500;

                // handle logging here
            }

            // always return a JSON result
            context.Result = new JsonResult(apiError);

            base.OnException(context);
        }
    }

```

But here I cannot do something like

```
private readonly ILogger _logger;
        public ApiExceptionFilter(ILogger logger)
        {
            _logger = logger;
        }

```

If I make above changes then

```
  [ApiController]
    [ApiExceptionFilter] //here it asking for paramter ilogger
    public class MyController : ControllerBase

```

In the above code [ApiExceptionFilter] It will ask for me to pass ILogger parameter.

I am just wondering what is the correct way to add ILogger in ApiExceptionFilter. Can someone help me in this. Any help would be appreciated. Thank you