In one of my project I had added delegate handler to log incoming and outgoing requests. For Logging I am using Nlog. I was generating a unique Id, per request to relate logs with this specific Id. This worked fine for me. Now recently I modified my code in handler, and set HttpContext.Currnet.Item value to this unique id. Now I am supposed to get this id, and pass it to external Apis.
Issue I faced is inside controller HttpContext.Current is null. I know what is the main root cause. This is because of handler.SendAsync, which will make the thread SynchronizationContext as null.
I want to pass HttpContext.Current to my ongoing threads.
What I did:
I set ConfigureAwait(false) I set appsettings -> aspnet:UseTraskFriendlySynchronizationContext to true
but these are not working.
I am using .net framework 4.7.1