Skip to content

Commit

Permalink
Support converting '.NET TP Worker' to the numeric thread ID on .NET 8+
Browse files Browse the repository at this point in the history
  • Loading branch information
erikmav committed Jan 12, 2024
1 parent e024c5c commit ab74a0a
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/log4net/Core/LoggingEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -736,17 +736,18 @@ public string ThreadName
m_data.ThreadName =
SystemInfo.CurrentThreadId.ToString(System.Globalization.NumberFormatInfo.InvariantInfo);
#else
// '.NET ThreadPool Worker' appears as a default thread pool name in .NET 6+.
// '.NET ThreadPool Worker' appears as a default thread name in the .NET 6-7 thread pool.
// '.NET TP Worker' is the default thread name in the .NET 8+ thread pool.
// Prefer the numeric thread ID instead.
string threadName = System.Threading.Thread.CurrentThread.Name;
if (!string.IsNullOrEmpty(threadName) && threadName != ".NET ThreadPool Worker")
if (!string.IsNullOrEmpty(threadName) && threadName != ".NET TP Worker" && threadName != ".NET ThreadPool Worker")
{
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
// go to the AppDomain to get the ID of the
// current thread. (Why don't Threads know their own ID?)
try
{
Expand Down

0 comments on commit ab74a0a

Please sign in to comment.