You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Provide a way of logging non-OK responses via ILogger.
Have a way to automatically call ILogger.LogError() on returning NotFound, Failed, etc. Note: this option must be off by default, as the sad path of end-points execution usually leads to logging anyway.
Thought to add an option of manually logging on the call of ToActionResult (the ILogger needs to be added in the parameters), but that seems to be unnecessary. If there's a pressing need to log a custom message, a logger must be injected into the corresponding method of the service layer.
The text was updated successfully, but these errors were encountered:
services.AddControllers().ConfigureApiBehaviorOptions(options =>{// To preserve the default behavior, capture the original delegate to call later.varbuiltInFactory=options.InvalidModelStateResponseFactory;options.InvalidModelStateResponseFactory= context =>{varlogger=context.HttpContext.RequestServices.GetRequiredService<ILogger<Startup>>();// Perform logging here.// ...// Invoke the default behavior, which produces a ValidationProblemDetails response.// To produce a custom response, return a different implementation of IActionResult instead.returnbuiltInFactory(context);};});
Need to consider a similar approach for ToActionResult().
Provide a way of logging non-OK responses via
ILogger
.Have a way to automatically call
ILogger.LogError()
on returningNotFound
,Failed
, etc. Note: this option must be off by default, as the sad path of end-points execution usually leads to logging anyway.Thought to add an option of manually logging on the call of
ToActionResult
(theILogger
needs to be added in the parameters), but that seems to be unnecessary. If there's a pressing need to log a custom message, a logger must be injected into the corresponding method of the service layer.The text was updated successfully, but these errors were encountered: