Persuading Kestrel to log my preferred handler name instead of "Wrapper"

19 Views Asked by At

I have a dot-net web service set up as follows:

using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;

var app = WebApplication.Create();
app.Urls.Add("http://localhost:3001");
app.MapGet("/", Wrap(IndexGetter));
/* Lots more app.MapGet calls, each using Wrap(). */
app.Run();

void Wrap(string pattern, Action<HttpContext> handler)
{
    return Wrapper;
    void Wrapper(HttpContext hc)
    {
         /* Wrapping stuff omitted. */
         handler(hc);
         /* More wrapping stuff. */
    }
}

This works great. The client calls a GET and the correct handler is called from inside the Wrapper function.

What's not good is what's logged.

Executed endpoint 'HTTP: GET /my/endpoint => Wrapper'

While technically correct, Wrapper is indeed the handler for this GET, I'd rather the name of the wrapped function was logged. Can I persuade it to think the handler has a different name?

0

There are 0 best solutions below