Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Log all request of Web API 2 (DelegatingHandler vs ActionFilterAttribute)

Log all request of Web API 2 (DelegatingHandler vs ActionFilterAttribute)

Scheduled Pinned Locked Moved ASP.NET
visual-studiocomsysadminwindows-adminalgorithms
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    Bastien Vandamme
    wrote on last edited by
    #1

    Searching on the web I found differents solutions to log all requests received by a IIS server. - Solution 1: [DelegatingHandler][1] - Solution 2: [ActionFilterAttribute][2] - Solution 3: [The IIS log][3] I read all articles about these differents solutions and I already implemented and tested them. I don't know wich one to choose between solution 1 and solution 2. Is there an history or performance or architecture maintenance reason that explain a solution is better than another. Are DelegatingHandler and/or ActionFilterAttribute a old feature? [1]: http://stackoverflow.com/a/23660832/196526 [2]: http://www.codeproject.com/Articles/1028416/RESTful-Day-sharp-Request-logging-and-Exception-ha [3]: https://msdn.microsoft.com/en-us/library/ms525410(v=vs.90).aspx

    B413

    Richard DeemingR 1 Reply Last reply
    0
    • B Bastien Vandamme

      Searching on the web I found differents solutions to log all requests received by a IIS server. - Solution 1: [DelegatingHandler][1] - Solution 2: [ActionFilterAttribute][2] - Solution 3: [The IIS log][3] I read all articles about these differents solutions and I already implemented and tested them. I don't know wich one to choose between solution 1 and solution 2. Is there an history or performance or architecture maintenance reason that explain a solution is better than another. Are DelegatingHandler and/or ActionFilterAttribute a old feature? [1]: http://stackoverflow.com/a/23660832/196526 [2]: http://www.codeproject.com/Articles/1028416/RESTful-Day-sharp-Request-logging-and-Exception-ha [3]: https://msdn.microsoft.com/en-us/library/ms525410(v=vs.90).aspx

      B413

      Richard DeemingR Offline
      Richard DeemingR Offline
      Richard Deeming
      wrote on last edited by
      #2

      If you want to log every request, then use the IIS log. That will include requests which might not be mapped to the Web API pipeline, and therefore wouldn't be picked up by a DelegatingHandler or action filter. If you just want to log the Web API requests, then either a DelegatingHandler or an action filter will work. Neither is an "old" feature. However, if you want to log the request and response bodies as a single entry, the DelegatingHandler would be the better choice.

      protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
      {
      var response = await base.SendAsync(request, cancellationToken);
      await LogAsync(request, response);
      return response;
      }

      If you just want trace logs for your code, have a look at Tracing in ASP.NET Web API 2[^].


      "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

      "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups