Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Always use thread id in agent logs #626

Merged
merged 5 commits into from
Jul 1, 2021

Conversation

JcolemanNR
Copy link
Contributor

Description

While testing out .NET 6, we noticed that thread names were being logged for .NET managed threads instead of the actually desired thread id in agent logfiles. This happened because Log4Net prefers to log a thread name versus a thread id, and Microsoft began setting thread names for their managed threads in .NET 6. The behavior is reproducible in previous versions of the product, but only if a user explicitly set the name of a thread.

The resolution is to check/set a thread id in the log4net thread context object, and update the logging layout to log this property. This is the same approach we use to log the process id, with the exception of only ever needing to set the process id once.

Resolves #600.

Testing

Unit tests were added to verify that the thread id property is set in log4net by every possible agent log binding. The .net core mvc async integration test application was updated to set a main thread name, and assertions were added in the text fixture to verify that this thread name, and the new .net background worker thread name does not show up in the log file instead of a thread id.

@JcolemanNR JcolemanNR requested a review from nr-ahemsath July 1, 2021 01:36
Copy link
Member

@nr-ahemsath nr-ahemsath left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. I did the following testing on this branch:

  1. Built the agent and ran the unit tests, which all passed except for one unrelated unit test which has been flickering (failing intermittently).
  2. Built the integration tests and ran them. All but 9 passed; the 9 failures were either related to package publishing issues caused by my having the .NET 6 preview 4 SDK installed, or are known bad tests (e.g. ThreadProfileStressTest).
  3. Manually tested running a .NET 6-targeted console app with the agent attached and examined the log file, and saw that it is now logging with the numeric thread id rather than the ".NET Threadpool Worker Thread" name.

🐑 it!

@JcolemanNR JcolemanNR merged commit eb4ae73 into main Jul 1, 2021
@JcolemanNR JcolemanNR deleted the jcoleman/always-use-threadid-in-logs branch July 1, 2021 22:31
vuqtran88 added a commit that referenced this pull request Jul 2, 2021
* Update all_solutions.yml

Allows creating deploy packages on a manual workflow run.

* Always use thread id in agent logs (#626)

* Add threadId property to log4net thread context, and change logging layout pattern to use this.

* Add unit tests to verify that threadid property is set for all logging bindings

* Add integration test coverage for the actual log output to the MVC async application test.

* Update Changelog

* Add exiftool tarball to repo and install it in container (#631)

Co-authored-by: Josh Coleman <83677148+JcolemanNR@users.noreply.github.com>
Co-authored-by: Alex Hemsath <57361211+nr-ahemsath@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

In .NET 6, thread ID in agent log shows generic name instead of numeric thread ID
2 participants