File tree Expand file tree Collapse file tree 1 file changed +7
-3
lines changed Expand file tree Collapse file tree 1 file changed +7
-3
lines changed Original file line number Diff line number Diff line change @@ -57,9 +57,7 @@ public static TEcsDocument CreateNewWithDefaults<TEcsDocument>(
5757
5858 if ( options ? . IncludeHost is null or true ) doc . Host = GetHost ( ) ;
5959 if ( options ? . IncludeProcess is null or true ) doc . Process = GetProcess ( ) ;
60- // TODO I think we can cache user? does CurrentPrincipal on Thread ever change?
61- if ( options ? . IncludeUser is null or true )
62- doc . User = new User { Id = Thread . CurrentPrincipal ? . Identity . Name , Name = Environment . UserName , Domain = Environment . UserDomainName } ;
60+ if ( options ? . IncludeUser is null or true ) doc . User = GetUser ( ) ;
6361
6462 return doc ;
6563 }
@@ -157,6 +155,12 @@ private static Process GetProcess()
157155 } ;
158156 }
159157
158+ private static readonly string UserName = Environment . UserName ;
159+ private static readonly string UserDomainName = Environment . UserDomainName ;
160+
161+ //Can not cache current thread's identity as it's used for role based security, different threads can have different identities
162+ private static User GetUser ( ) => new User { Id = Thread . CurrentPrincipal ? . Identity . Name , Name = UserName , Domain = UserDomainName } ;
163+
160164 private static Error GetError ( Exception exception )
161165 {
162166 if ( exception == null )
You can’t perform that action at this time.
0 commit comments