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 2021/12/16 06:58:33 UTC
[logging-log4net] branch master updated: For %thread/%t, use the numeric thread ID for .NET worker pool threads
This is an automated email from the ASF dual-hosted git repository.
davydm pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/logging-log4net.git
The following commit(s) were added to refs/heads/master by this push:
new a17282a For %thread/%t, use the numeric thread ID for .NET worker pool threads
new 0b9f537 Merge pull request #78 from erikma/dev/erikmav/net6ThreadName
a17282a is described below
commit a17282a45509cd8d23695ded3938958cfe21ccd0
Author: Erik Mavrinac <er...@microsoft.com>
AuthorDate: Wed Dec 1 11:29:29 2021 -0800
For %thread/%t, use the numeric thread ID for .NET worker pool threads
---
src/log4net/Core/LoggingEvent.cs | 14 ++++++++++----
1 file changed, 10 insertions(+), 4 deletions(-)
diff --git a/src/log4net/Core/LoggingEvent.cs b/src/log4net/Core/LoggingEvent.cs
index 4ad16f1..678e62e 100644
--- a/src/log4net/Core/LoggingEvent.cs
+++ b/src/log4net/Core/LoggingEvent.cs
@@ -835,10 +835,16 @@ namespace log4net.Core
m_data.ThreadName =
SystemInfo.CurrentThreadId.ToString(System.Globalization.NumberFormatInfo.InvariantInfo);
#else
- m_data.ThreadName = System.Threading.Thread.CurrentThread.Name;
- if (m_data.ThreadName == null || m_data.ThreadName.Length == 0)
+ // '.NET ThreadPool Worker' appears as a default thread pool name in .NET 6+.
+ // Prefer the numeric thread ID instead.
+ string threadName = System.Threading.Thread.CurrentThread.Name;
+ if (!string.IsNullOrEmpty(threadName) && threadName != ".NET ThreadPool Worker")
{
- // The thread name is not available. Therefore we
+ m_data.ThreadName = threadName;
+ }
+ else
+ {
+ // The thread name is not available or unsuitable. Therefore we
// go the the AppDomain to get the ID of the
// current thread. (Why don't Threads know their own ID?)
try
@@ -847,7 +853,7 @@ namespace log4net.Core
SystemInfo.CurrentThreadId.ToString(System.Globalization.NumberFormatInfo
.InvariantInfo);
}
- catch (System.Security.SecurityException)
+ catch (SecurityException)
{
// This security exception will occur if the caller does not have
// some undefined set of SecurityPermission flags.