In a WebAPI Self-Host application, will SendAsync() method of DelegatingHandler and any method of ApiController always execute on the same thread?
Is it safe to use [ThreadStatic] variable to pass RequestId from SessionHandler to TestController ?
Example:
public class TestController : ApiController { [HttpGet] public string Run() { LogManager.GetLogger("Controller").InfoFormat("Thread id: {0} ", Thread.CurrentThread.ManagedThreadId); return "Bar"; } } public class SessionHandler : DelegatingHandler { protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) { LogManager.GetLogger("SessionHandler").InfoFormat("Thread id: {0} ", Thread.CurrentThread.ManagedThreadId); return await base.SendAsync(request, cancellationToken); } }