Skip to content

Provide a way for users to turn on logging for formatting, to help resolve bugs#12304

Merged
davidwengier merged 17 commits intodotnet:mainfrom
davidwengier:FormattingLogging
Oct 12, 2025
Merged

Provide a way for users to turn on logging for formatting, to help resolve bugs#12304
davidwengier merged 17 commits intodotnet:mainfrom
davidwengier:FormattingLogging

Conversation

@davidwengier
Copy link
Member

We've gotten a couple of reports recently of formatting issues that have shown bugs in the formatting engine, but that haven't reproduced when trying the same scenario locally. I took some inspiration from the Edit and Continue logging infra, and things like complog and binlog, and wanted to create something so that we can ask users to turn on "formatting logging", and get a bunch of data out of the system that we can use to essentially replay what happened on their machine.

We already had most of this logging for tests, and it has proven invaluable in the past for fixing these issues, assuming a failing test can be created. Hopefully now that we can get the same logging from users, we will always be able to get a failing test. But sadly, only time will tell, because I can't repro the issues in order to test that the logging is enough to repro the issues 😂

@davidwengier davidwengier requested a review from a team as a code owner October 9, 2025 10:55
}
catch (IOException)
{
// Swallow IO exceptions, logging is best effort
Copy link
Member

Choose a reason for hiding this comment

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

While it's a best effort, it feels like we could probably do a bit better than this. As written, every LogObject and LogSourceText for the same name will throw because FileMode.CreateNew is used. Would it be better to just stomp on old files?

Copy link
Member Author

Choose a reason for hiding this comment

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

Thank you for this comment, doing it this way was a deliberate choice but I completely failed to remember that and missed adding something to the test logger. My thinking was that its trivial for us to ensure that names are unique, and our test logger can validate that, therefore we don't need to worry about doing file exists checks, or logic to find unique file names etc. If we come up with a scenario later that we want to stomping on old files, I would think that should be an explicit choice via an API of some kind.

@davidwengier
Copy link
Member Author

Thanks for all the feedback, especially around the documentation. This is ready for a second look (and should build now!)

Copy link
Contributor

@ToddGrun ToddGrun left a comment

Choose a reason for hiding this comment

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

:shipit:

@davidwengier davidwengier merged commit f63acaa into dotnet:main Oct 12, 2025
11 checks passed
@davidwengier davidwengier deleted the FormattingLogging branch October 12, 2025 21:07
@dotnet-policy-service dotnet-policy-service bot added this to the Next milestone Oct 12, 2025
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.

3 participants