Skip to content

Commit

Permalink
🐛 should fall back on Environment.UserName if !win32
Browse files Browse the repository at this point in the history
  • Loading branch information
fluffynuts committed Oct 18, 2020
1 parent 141b00b commit e137855
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/log4net/Core/LoggingEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -914,7 +914,7 @@ public string ThreadName
/// </para>
/// </remarks>
public string UserName =>
m_data.UserName ??= TryGetCurrentUserName();
m_data.UserName ??= TryGetCurrentUserName() ?? SystemInfo.NotAvailableText;

private static string TryGetCurrentUserName()
{
Expand All @@ -929,8 +929,7 @@ private static string TryGetCurrentUserName()
}
catch (PlatformNotSupportedException)
{
// TODO: on a platform which supports it, invoke `whoami`
return SystemInfo.NotAvailableText;
return Environment.UserName;
}
catch (SecurityException)
{
Expand All @@ -940,12 +939,15 @@ private static string TryGetCurrentUserName()
declaringType,
"Security exception while trying to get current windows identity. Error Ignored. Empty user name."
);

return SystemInfo.NotAvailableText;
return null;
}
catch
{
return null;
}
#endif
}

/// <summary>
/// Gets the identity of the current thread principal.
/// </summary>
Expand Down

0 comments on commit e137855

Please sign in to comment.