-1

I am trying to log elapsed time for each request(.net core 2.2) in my configure method like this:

public void Configure(IApplicationBuilder app, IHostingEnvironment env, 
    ILoggerFactory loggerFactory)
{
    app.Use(async (context, next) =>
    {
        Logging.Log.Id = Convert.ToString(new Activity(string.Empty).Id);

        var sw = new Stopwatch();
        sw.Start();
        await next.Invoke();
        sw.Stop();

        Logging.Log.Info($"ElapsedTime: {sw.ElapsedMilliseconds}");
    });

    // rest of method code omitted 
} 

Along with elapsed time I want to display which endpoint was called or absolute uri where the request is headed to. How can I get the same here from context object.

Arcanox
  • 1,420
  • 11
  • 20
Gautam
  • 363
  • 1
  • 4
  • 15
  • 2
    `context.Request.Path`... You can read more [here](https://learn.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.http.httprequest?view=aspnetcore-2.2) – Trevor Apr 09 '19 at 17:52

1 Answers1

1

Your context parameter has a Request property, which has all the information you could want about which URL the client is calling.

You can follow this post to help you construct a raw url, or just use the pieces that object gives you.

gunr2171
  • 16,104
  • 25
  • 61
  • 88