Recently I have integrated MiniProfiler into a .NET 6 API and all works well, can see the SQL queries via EFCore and all on the dashboard. What I would like to achieve now is that the profiler still profiles all HTTP requests like it does now, but when an error happens anywhere in the application (Status code != 200) I would want to do some custom stuff with the profiler data, for example save the profiler trace (same stuff that's shown on the dashboard) to a DB or logger.
What I had in mind initially was to make a custom middleware, and then after await _next(context);
fetch the data (duration time, steps, types, queries) from the profiler from MiniProfiler.Current
but I can't seem to make it work. Any solutions?