Skip to content

Commit e137855

Browse files
committed
🐛 should fall back on Environment.UserName if !win32
1 parent 141b00b commit e137855

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

src/log4net/Core/LoggingEvent.cs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -914,7 +914,7 @@ public string ThreadName
914914
/// </para>
915915
/// </remarks>
916916
public string UserName =>
917-
m_data.UserName ??= TryGetCurrentUserName();
917+
m_data.UserName ??= TryGetCurrentUserName() ?? SystemInfo.NotAvailableText;
918918

919919
private static string TryGetCurrentUserName()
920920
{
@@ -929,8 +929,7 @@ private static string TryGetCurrentUserName()
929929
}
930930
catch (PlatformNotSupportedException)
931931
{
932-
// TODO: on a platform which supports it, invoke `whoami`
933-
return SystemInfo.NotAvailableText;
932+
return Environment.UserName;
934933
}
935934
catch (SecurityException)
936935
{
@@ -940,12 +939,15 @@ private static string TryGetCurrentUserName()
940939
declaringType,
941940
"Security exception while trying to get current windows identity. Error Ignored. Empty user name."
942941
);
943-
944-
return SystemInfo.NotAvailableText;
942+
return null;
943+
}
944+
catch
945+
{
946+
return null;
945947
}
946948
#endif
947949
}
948-
950+
949951
/// <summary>
950952
/// Gets the identity of the current thread principal.
951953
/// </summary>

0 commit comments

Comments
 (0)