Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8388503
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T18:29:09+00:00 2026-06-09T18:29:09+00:00

I created a message handler which will log the request and the response. ideally

  • 0

I created a message handler which will log the request and the response. ideally I want to

public class LoggingMessageHandler : DelegatingHandler
{
    protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
    {
        LogRequest(request);

        return base.SendAsync(request, cancellationToken).ContinueWith(task =>
        {
            var response = task.Result;

            LogResponse(response);

            return response;
        });
    }

    private void LogRequest(HttpRequestMessage request)
    {
        var writer = request.GetConfiguration().Services.GetTraceWriter();
        var content = request.Content;

        (content ?? new StringContent("")).ReadAsStringAsync().ContinueWith(x =>
        {
            writer.Trace(request, "request", System.Web.Http.Tracing.TraceLevel.Info, t =>
            {
                t.Message = x.Result;
            });
        });
    }

    private void LogResponse(HttpResponseMessage response)
    {
        var request = response.RequestMessage;
        var writer = request.GetConfiguration().Services.GetTraceWriter();
        var content = response.Content;

        (content ?? new StringContent("")).ReadAsStringAsync().ContinueWith(x =>
        {
            writer.Trace(request, "response", System.Web.Http.Tracing.TraceLevel.Info, t => 
            {
                t.Status = response.StatusCode;
                t.Message = x.Result;
            });
        });
    }
}

and here is my client code.

public ActionResult Index()
{
    var profile = Client.GetAsync("Vendor").Result.EnsureSuccessStatusCode().Content.ReadAsAsync<VendorProfileModel>().Result;
    return View(profile);
}

Logging appears to be working. However, when this handler is registered my client code returns an empty object. If I remove this handler the model is successfully read from the response and displayed on screen.

Is there a way to read the content and display the results on the client?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T18:29:10+00:00Added an answer on June 9, 2026 at 6:29 pm

    after a few more days for digging around on the net I finally found the root problem and a solution. First the problem:

    1. everything in webapi is async
    2. my action uses Controller.User which in turn is calling Thread.CurrentPrinciple
    3. I am using ITraceWriter as my logging abstraction

    apparently there is a bug in the ITraceWriter mechanicism where the current profile is not propagated across threads. therefore, i loose the principle when i get to my controller action. therefore, my query returns an empty result, rather than a fully populated result.

    solution: don’t use ITraceWriter to log messages. It would have been nice to use the built in mechanics, but that doesn’t work. here is the link to the same issue which provides more detail/context.

    https://aspnetwebstack.codeplex.com/workitem/237

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My sql table is something like (message,created) I want to select those rows which
I want to use a configuration file to create two loggers which will log
I've created a miniature 'web server' that simply returns one message to any request
Hi I have created a zend_form_element_submit. Now i want to display a confirmation message
I declared a delegate: public delegate void Del(string message); Then i created a function
The MSDN site says: From your view class's function that handles the WM_CREATE message
I am struggling with the following scenario: an XML-message is created client-side and digitally
I have this in a MySQL db: table Message sender_id int recipient_id int created
I cannot update created previously entity. I'm getting a StaleObjectException exception with message: Row
I have created an inbox system. Signed in user can message other signed in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.