Uploaded image for project: 'Log4net'
  1. Log4net
  2. LOG4NET-695

LoggingEvent - ThreadName calculated incorrectly in .net8

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Minor
    • Resolution: Unresolved
    • 2.0.14
    • None
    • Core
    • None

    Description

      Version:

      log4net 2.0.15
      

      Problematic code:
      https://github.com/apache/logging-log4net/blob/master/src/log4net/Core/LoggingEvent.cs

        public string ThreadName
              {
                  get
                  {
                      if (m_data.ThreadName == null && this.m_cacheUpdatable)
                      {
      #if NETCF
      					// Get thread ID only
      					m_data.ThreadName =
       SystemInfo.CurrentThreadId.ToString(System.Globalization.NumberFormatInfo.InvariantInfo);
      #else
                          // '.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")
                          {
                              m_data.ThreadName = threadName;
                          }
      

      In .NET 8 the threads from thread pool have new name: ".NET TP Worker".

      So probably additional condition in this code is required:

      if (!string.IsNullOrEmpty(threadName) && threadName != ".NET ThreadPool Worker" && threadName != ".NET TP Worker")
      

      Attachments

        Activity

          People

            Unassigned Unassigned
            micrak Michal Rakoczy
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated: