FreeAndNil commented on code in PR #199: URL: https://github.com/apache/logging-log4net/pull/199#discussion_r1807940150
########## src/log4net/Core/LoggingEvent.cs: ########## @@ -742,15 +742,27 @@ private static string ReviseThreadName(string? threadName) { if (_platformDoesNotSupportWindowsIdentity) { - // we've already received one PlatformNotSupportedException + // we've already received one PlatformNotSupportedException or null from TryReadWindowsIdentityUserName // and it's highly unlikely that will change return Environment.UserName; } try { - return _cachedWindowsIdentityUserName ??= - TryReadWindowsIdentityUserName(); + if(_cachedWindowsIdentityUserName is not null) + { + return _cachedWindowsIdentityUserName; + } + else if(TryReadWindowsIdentityUserName() is string userName) + { + _cachedWindowsIdentityUserName = userName; + return _cachedWindowsIdentityUserName; + } + else + { Review Comment: ```suggestion ``` ########## src/log4net/Core/LoggingEvent.cs: ########## @@ -742,15 +742,27 @@ private static string ReviseThreadName(string? threadName) { if (_platformDoesNotSupportWindowsIdentity) { - // we've already received one PlatformNotSupportedException + // we've already received one PlatformNotSupportedException or null from TryReadWindowsIdentityUserName // and it's highly unlikely that will change return Environment.UserName; } try { - return _cachedWindowsIdentityUserName ??= - TryReadWindowsIdentityUserName(); + if(_cachedWindowsIdentityUserName is not null) + { + return _cachedWindowsIdentityUserName; + } + else if(TryReadWindowsIdentityUserName() is string userName) Review Comment: ```suggestion if (TryReadWindowsIdentityUserName() is string userName) ``` ########## src/log4net/Core/LoggingEvent.cs: ########## @@ -742,15 +742,27 @@ private static string ReviseThreadName(string? threadName) { if (_platformDoesNotSupportWindowsIdentity) { - // we've already received one PlatformNotSupportedException + // we've already received one PlatformNotSupportedException or null from TryReadWindowsIdentityUserName // and it's highly unlikely that will change return Environment.UserName; } try { - return _cachedWindowsIdentityUserName ??= - TryReadWindowsIdentityUserName(); + if(_cachedWindowsIdentityUserName is not null) + { + return _cachedWindowsIdentityUserName; + } + else if(TryReadWindowsIdentityUserName() is string userName) + { + _cachedWindowsIdentityUserName = userName; + return _cachedWindowsIdentityUserName; + } + else + { + _platformDoesNotSupportWindowsIdentity = true; + return Environment.UserName; Review Comment: ```suggestion return Environment.UserName; ``` ########## src/log4net/Core/LoggingEvent.cs: ########## @@ -742,15 +742,27 @@ private static string ReviseThreadName(string? threadName) { if (_platformDoesNotSupportWindowsIdentity) { - // we've already received one PlatformNotSupportedException + // we've already received one PlatformNotSupportedException or null from TryReadWindowsIdentityUserName // and it's highly unlikely that will change return Environment.UserName; } try { - return _cachedWindowsIdentityUserName ??= - TryReadWindowsIdentityUserName(); + if(_cachedWindowsIdentityUserName is not null) + { + return _cachedWindowsIdentityUserName; + } + else if(TryReadWindowsIdentityUserName() is string userName) + { + _cachedWindowsIdentityUserName = userName; + return _cachedWindowsIdentityUserName; + } + else + { + _platformDoesNotSupportWindowsIdentity = true; Review Comment: ```suggestion _platformDoesNotSupportWindowsIdentity = true; ``` ########## src/log4net/Core/LoggingEvent.cs: ########## @@ -742,15 +742,27 @@ private static string ReviseThreadName(string? threadName) { if (_platformDoesNotSupportWindowsIdentity) { - // we've already received one PlatformNotSupportedException + // we've already received one PlatformNotSupportedException or null from TryReadWindowsIdentityUserName Review Comment: Can you fix the comment on UserName (especially clarify the "NOT AVAILABLE" part)? ########## src/log4net/Core/LoggingEvent.cs: ########## @@ -742,15 +742,27 @@ private static string ReviseThreadName(string? threadName) { if (_platformDoesNotSupportWindowsIdentity) { - // we've already received one PlatformNotSupportedException + // we've already received one PlatformNotSupportedException or null from TryReadWindowsIdentityUserName // and it's highly unlikely that will change return Environment.UserName; } try { - return _cachedWindowsIdentityUserName ??= - TryReadWindowsIdentityUserName(); + if(_cachedWindowsIdentityUserName is not null) Review Comment: ```suggestion if (_cachedWindowsIdentityUserName is not null) ``` ########## src/log4net/Core/LoggingEvent.cs: ########## @@ -742,15 +742,27 @@ private static string ReviseThreadName(string? threadName) { if (_platformDoesNotSupportWindowsIdentity) { - // we've already received one PlatformNotSupportedException + // we've already received one PlatformNotSupportedException or null from TryReadWindowsIdentityUserName // and it's highly unlikely that will change return Environment.UserName; } try { - return _cachedWindowsIdentityUserName ??= - TryReadWindowsIdentityUserName(); + if(_cachedWindowsIdentityUserName is not null) + { + return _cachedWindowsIdentityUserName; + } + else if(TryReadWindowsIdentityUserName() is string userName) + { + _cachedWindowsIdentityUserName = userName; + return _cachedWindowsIdentityUserName; + } + else + { + _platformDoesNotSupportWindowsIdentity = true; + return Environment.UserName; + } Review Comment: ```suggestion ``` ########## src/log4net/Core/LoggingEvent.cs: ########## @@ -742,15 +742,27 @@ private static string ReviseThreadName(string? threadName) { if (_platformDoesNotSupportWindowsIdentity) { - // we've already received one PlatformNotSupportedException + // we've already received one PlatformNotSupportedException or null from TryReadWindowsIdentityUserName // and it's highly unlikely that will change return Environment.UserName; } try { - return _cachedWindowsIdentityUserName ??= - TryReadWindowsIdentityUserName(); + if(_cachedWindowsIdentityUserName is not null) + { + return _cachedWindowsIdentityUserName; + } + else if(TryReadWindowsIdentityUserName() is string userName) + { + _cachedWindowsIdentityUserName = userName; + return _cachedWindowsIdentityUserName; + } + else Review Comment: ```suggestion ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@logging.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org