2

I have old known problem with log4net and Web-Api. The problem is, that Web-Api is async and therefor the standard way with LogicalThreadContext and ThreadContext is not reliable for logging Request related stuff (eg. BrowserAgent, Ip, ...). Note that in MVC or WebForms this usually works, but Web-Api not.

I was inspired by these links for solution: http://piers7.blogspot.de/2005/12/log4net-context-problems-with-aspnet.html and Capture username with log4net (and some similar solutions in other links)

First time it seemed to be a great idea with storing values on HttpContext and use a ValueProvider to get them from GlobalContext, but even this is not working good :(

The Problem is: log4net logs into Database delayed => these ValueProviders are asked later for their values, so the values are not from current HttpContext but some other context and are totaly missleading.

Has anyone found final 100% working solution for this? It would save my nerves.. Thanks a lot

Community
  • 1
  • 1
Lukas K
  • 5,198
  • 4
  • 17
  • 27

1 Answers1

0

Regarding to my other question here: Using HttpContext.Current in WebApi is dangerous because of async now I know it is safe to store the data in HttpContext.Current so it works now as desired..

Community
  • 1
  • 1
Lukas K
  • 5,198
  • 4
  • 17
  • 27