Closed Raj4git closed 3 years ago
Hi,
this enrichers really only adds as a log property the contents of HttpContext.Current.User
. Can you confirm that HttpContext.Current.User
is actually set for your web api calls ?
There are also two username fields in that screenshot, looks like you might be confusing "UserName" and "Username" (notice the slight case sensitivity difference).
"Username"(derived using HttpContext.Current.User) is manually pushed in the logs before it write. "UserName" gets added by web classic enricher. I suspect its a cross-thread issue. :(
Not quite sure I understand what you mean when you say :
for any service/web api calls from the app it doesn't get log
Could you paste some snippets of the code that writes down those logs ?
When we land on our home page we call a web API. We are trying to log the username when we call API along with api request-response and other details. I can see serilog configured to log user name correctly showing username for httpmodule logs but not showing username for the web api logs. Sorry cant add code.
@Raj4git thanks for the bug report.
To be honest, I really don't know what could be causing it, and therefore how to fix it :-/
To retrieve the user, we actually do something like :
(new HttpContextWrapper(HttpContext.Current)).User
does this return something different in your case of a service call ?
My guess is @Raj4git has not actually inspected the .User property that @tsimbalar is referencing.
@Raj4git is indicating this is a web api. My bet is he is authenticating via Identity Server. It doesn't wire itself up by default to hydrate the Username property upon receiving JWT tokens... You have to do some manual magic to make that happen. So in essence @Raj4git username property is null because of incorrect configuration of his Web API configuration.
Closing for lack of activity. Happy to re-open if needed
I have configured logging with below values .Enrich.WithUserName(noneUsername: "not found") .Enrich.WithClaimValue(ClaimTypes.NameIdentifier, "TestUserName");
Its getting logged correctly when code logs HTTP calls but for any service/web api calls from the app it doesn't get log