serilog-web / classic

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

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Using the EnvironmentUserName if none?

rocknet opened this issue · comments

Would you be open to a PR which uses a specified LogEvent Property as the "noneUsername"? Ideally (for us) what we'd get is during app initialization or other non-HttpRequest threads (like a scheduled task) the UserName would provide EnvironmentUserName rather than null (rendered as blank in log files).

I tried setting the noneUsername to %USERDOMAIN%\%USERNAME%, but I assume since that is expanded at a different part of the app lifecycle, %USERNAME% is actually <mymachinename>$, rather than the user that w3wp is running as - which is correctly set with the EnvironmentUserName enricher.

We could hard code it as the service account user name, but that's a new maintenance issue for the various environments. I'd also rather be able to do this in the outputTemplate, but from what I can see that's not possible something like {UserName ?? EnvironmentUserName} would work, but that's for another project.

Hi @rocknet - the best option in this scenario might be to implement your own Serilog ILogEventEnricher that plugs in, checks for the existence of a valid username property, and creates one from the alternative property if none exists. Does this sound viable? Thansk!

Sure, that's definitely an option if you don't see it adding value here. Thanks