You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by da...@apache.org on 2020/10/18 15:24:22 UTC
[logging-log4net] 01/03: :bug: should fall back on
Environment.UserName if !win32
This is an automated email from the ASF dual-hosted git repository.
davydm pushed a commit to tag rc/2.0.12
in repository https://gitbox.apache.org/repos/asf/logging-log4net.git
commit cbc4d6ccf98394e014e7461c791c4a642db1be9e
Author: Davyd McColl <da...@gmail.com>
AuthorDate: Sun Oct 18 17:19:10 2020 +0200
:bug: should fall back on Environment.UserName if !win32
---
src/log4net/Core/LoggingEvent.cs | 14 ++++++++------
1 file changed, 8 insertions(+), 6 deletions(-)
diff --git a/src/log4net/Core/LoggingEvent.cs b/src/log4net/Core/LoggingEvent.cs
index 665700e..02eed28 100644
--- a/src/log4net/Core/LoggingEvent.cs
+++ b/src/log4net/Core/LoggingEvent.cs
@@ -914,7 +914,7 @@ namespace log4net.Core
/// </para>
/// </remarks>
public string UserName =>
- m_data.UserName ??= TryGetCurrentUserName();
+ m_data.UserName ??= TryGetCurrentUserName() ?? SystemInfo.NotAvailableText;
private static string TryGetCurrentUserName()
{
@@ -929,8 +929,7 @@ namespace log4net.Core
}
catch (PlatformNotSupportedException)
{
- // TODO: on a platform which supports it, invoke `whoami`
- return SystemInfo.NotAvailableText;
+ return Environment.UserName;
}
catch (SecurityException)
{
@@ -940,12 +939,15 @@ namespace log4net.Core
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>