Log request URI in ASP.NET Web API

26 May

If you want to know how your users call your ASP.NET Web API you can hook into the process by implementing a custom Message Handler. This is done by creating a class that inherits from DelegatingHandler. In the overwritten SendAsync method you can implement your logging structure:

public class UrlCallLogger : DelegatingHandler
    protected override Task<HttpResponseMessage> SendAsync(
                                HttpRequestMessage request,
                                CancellationToken cancellationToken)
        // do more with your logging
        // [...]
        return base.SendAsync(request, cancellationToken);

Then in the Register method of the WebApiConfig class you have to add following line:

config.MessageHandlers.Add(new UrlCallLogger());

About how to config

Leave a comment

Posted by on May 26, 2015 in C-Sharp



Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: