serilog-web / classic

Serilog web request logging and enrichment for classic ASP.NET applications

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

UserName enricher shows (anonymous) in ApplicationLifecycleModule with Microsoft.AspNet.WebApi.* >= 5.2.5

stanisls opened this issue · comments

Microsoft made some changes in Microsoft.AspNet.WebApi.* version >= 5.2.5, which result in UserName enricher showing (anonymous) on the final log event, issued for ApplicationLifecycleModule, while all other events in the same context have the value of the authenticated API user.

My project ran initially on version 5.2.4, and after updating it to 5.2.6, I noticed the problem. I identified that the problem first appeared in 5.2.5 of Microsoft.AspNet.WebApi.* packages.

It looks like the user in HttpContext.Current holds user identity that is no longer authenticated at the time OnLogRequest is executed

Thanks for reporting the issue and taking to identify the breaking change.

I am kind of wondering if Microsoft.AspNet.WebApi v5.2.6 was really officially released, given I cannot find any announcement about it anywhere... (here is the one for v5.2.5 : announcement )

I would say this change they introduced is a breaking change and is probably a bug. Could you maybe open an issue at https://github.com/aspnet/AspNetWebStack ?

I've updated the title to be more explicit - the problem seemes to have been introduced in 5.2.5. I rolled first back from 5.2.6 to 5.2.5, and the problem was still there. Rolled then back one more step to 5.2.4, and the UseName stated being logged correctly.

Managed to reproduce in a clean minimalistic application.
webapibug

This was caused by config.SuppressHostPrincipal(); and 5.2.5 implementing a fix that honours the setting.
I guess this is not-a-bug in SerilogWeb.Classic as well, but rather the correct behaviour.

Yes :)
I'll close this issue but it's good to know about this in case it happens again :)