Modernize next System.Diagnostics C# snippets - #13033
Conversation
Update the second batch of 60 System.Diagnostics C# samples to current syntax and consolidate their net10.0 snippet projects while preserving the documented APIs and runtime behavior. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 81f0fa5e-3bcf-4d3b-b652-f7dc76e7ae03
There was a problem hiding this comment.
Pull request overview
This PR modernizes a batch of System.Diagnostics C# API-reference snippets to compile cleanly as .NET 10 snippet projects while keeping the demonstrated APIs intact. The updates primarily replace legacy patterns (WinForms scaffolding, older formatting, multiple Main entry points) with current C# syntax and consolidated executable entry points.
Changes:
- Convert many snippet projects from
Library/net10.0-windowstoExe/net10.0, adding consolidationProgram.csentry points where multiple snippet files exist. - Modernize snippet code: top-level statements/file-scoped namespaces, string interpolation, target-typed
new,usingdisposal patterns, and removal of unused usings/WinForms scaffolding. - Adjust project dependencies to match the APIs used (for example,
System.Diagnostics.EventLogfor EventLog samples) and prune unnecessary package references.
Reviewed changes
Copilot reviewed 107 out of 110 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
| snippets/csharp/System.Diagnostics/PerformanceCounterCategory/GetCategories/Project.csproj | Switch project to Exe/net10.0 for consolidated execution. |
| snippets/csharp/System.Diagnostics/PerformanceCounterCategory/GetCategories/Program.cs | Add entry point that runs multiple GetCategories-related snippets. |
| snippets/csharp/System.Diagnostics/PerformanceCounterCategory/GetCategories/perfcountergetcat.cs | Modernize formatting, error output, and control flow; Main → Run. |
| snippets/csharp/System.Diagnostics/PerformanceCounterCategory/GetCategories/perfcountercatgetinst.cs | Modernize code and convert to Run method for consolidation. |
| snippets/csharp/System.Diagnostics/PerformanceCounterCategory/GetCategories/perfcountercatgetcount.cs | Modernize code; add disposal of PerformanceCounter instances. |
| snippets/csharp/System.Diagnostics/PerformanceCounterCategory/Create/Project.csproj | Switch project to Exe/net10.0 with PerformanceCounter package reference retained. |
| snippets/csharp/System.Diagnostics/PerformanceCounterCategory/Create/program.cs | Modernize sample code and add consolidated Program entry point. |
| snippets/csharp/System.Diagnostics/PerformanceCounterCategory/Create/ccd.cs | Modernize object/collection initialization; Main → Run. |
| snippets/csharp/System.Diagnostics/PerformanceCounterCategory/CounterExists/Project.csproj | Switch project to Exe/net10.0 for consolidated execution. |
| snippets/csharp/System.Diagnostics/PerformanceCounterCategory/CounterExists/Program.cs | Add entry point that runs multiple CounterExists-related snippets. |
| snippets/csharp/System.Diagnostics/PerformanceCounterCategory/CounterExists/perfcounterobjinstexists.cs | Modernize code and convert to Run; remove unused VB dependency. |
| snippets/csharp/System.Diagnostics/PerformanceCounterCategory/CounterExists/perfcountercatstatinstexists.cs | Modernize code and convert to Run; remove unused VB dependency. |
| snippets/csharp/System.Diagnostics/PerformanceCounterCategory/CounterExists/perfcountercatstatcounterexists.cs | Modernize code and convert to Run; remove unused VB dependency. |
| snippets/csharp/System.Diagnostics/PerformanceCounterCategory/CounterExists/perfcountercatobjexists.cs | Modernize code and convert to Run; remove unused VB dependency. |
| snippets/csharp/System.Diagnostics/PerformanceCounterCategory/CounterExists/percounterexists.cs | Modernize code and convert to Run; update output formatting. |
| snippets/csharp/System.Diagnostics/PerformanceCounterCategory/.ctor/Project.csproj | Switch project to Exe/net10.0 for consolidated execution. |
| snippets/csharp/System.Diagnostics/PerformanceCounterCategory/.ctor/Program.cs | Add entry point that runs ctor/props/delete related snippets. |
| snippets/csharp/System.Diagnostics/PerformanceCounterCategory/.ctor/perfCounterCatProps.cs | Modernize code and convert to Run; update formatting. |
| snippets/csharp/System.Diagnostics/PerformanceCounterCategory/.ctor/perfCounterCatDelete.cs | Modernize code and convert to Run; update output formatting. |
| snippets/csharp/System.Diagnostics/PerformanceCounterCategory/.ctor/perfcountercatctor.cs | Modernize constructor selection logic and convert to Run. |
| snippets/csharp/System.Diagnostics/PerformanceCounter/NextValue/Project.csproj | Switch project to Exe/net10.0. |
| snippets/csharp/System.Diagnostics/PerformanceCounter/NextValue/elapsedtime.cs | Modernize formatting and APIs used; add disposal pattern and explicit types. |
| snippets/csharp/System.Diagnostics/PerformanceCounter/.ctor/Project.csproj | Switch project to Exe/net10.0. |
| snippets/csharp/System.Diagnostics/PerformanceCounter/.ctor/perfcounter.cs | Replace WinForms sample with console/top-level snippet while preserving API usage. |
| snippets/csharp/System.Diagnostics/InstanceDataCollectionCollection/Contains/Project.csproj | Switch project to Exe/net10.0. |
| snippets/csharp/System.Diagnostics/InstanceDataCollectionCollection/Contains/instdatacolcolitermcontains.cs | Modernize formatting and control flow; improve snippet marker placement. |
| snippets/csharp/System.Diagnostics/InstanceDataCollection/Overview/Project.csproj | Switch project to Exe/net10.0. |
| snippets/csharp/System.Diagnostics/InstanceDataCollection/Overview/instdatakeysvalues.cs | Modernize formatting and object creation patterns. |
| snippets/csharp/System.Diagnostics/InstanceDataCollection/Contains/Project.csproj | Switch project to Exe/net10.0. |
| snippets/csharp/System.Diagnostics/InstanceDataCollection/Contains/instdatacolitemcontains.cs | Modernize formatting/control flow; update constants and object creation. |
| snippets/csharp/System.Diagnostics/InstanceData/Overview/Project.csproj | Switch project to Exe/net10.0. |
| snippets/csharp/System.Diagnostics/InstanceData/Overview/instdatacopyto.cs | Modernize formatting and object creation patterns. |
| snippets/csharp/System.Diagnostics/FileVersionInfo/ToString/source.cs | Convert WinForms snippet to console/top-level and modernize path handling. |
| snippets/csharp/System.Diagnostics/FileVersionInfo/ToString/Project.csproj | Switch project to Exe/net10.0; remove unnecessary PerformanceCounter package. |
| snippets/csharp/System.Diagnostics/FileVersionInfo/SpecialBuild/source.cs | Convert WinForms snippet to console/top-level and modernize path handling. |
| snippets/csharp/System.Diagnostics/FileVersionInfo/SpecialBuild/Project.csproj | Switch project to Exe/net10.0; remove unnecessary PerformanceCounter package. |
| snippets/csharp/System.Diagnostics/FileVersionInfo/ProductVersion/source.cs | Convert WinForms snippet to console/top-level and modernize path handling. |
| snippets/csharp/System.Diagnostics/FileVersionInfo/ProductVersion/Project.csproj | Switch project to Exe/net10.0; remove unnecessary PerformanceCounter package. |
| snippets/csharp/System.Diagnostics/FileVersionInfo/ProductPrivatePart/source.cs | Convert WinForms snippet to console/top-level and modernize path handling. |
| snippets/csharp/System.Diagnostics/FileVersionInfo/ProductPrivatePart/Project.csproj | Switch project to Exe/net10.0; remove unnecessary PerformanceCounter package. |
| snippets/csharp/System.Diagnostics/FileVersionInfo/ProductName/source.cs | Convert WinForms snippet to console/top-level and modernize path handling. |
| snippets/csharp/System.Diagnostics/FileVersionInfo/ProductName/Project.csproj | Switch project to Exe/net10.0; remove unnecessary PerformanceCounter package. |
| snippets/csharp/System.Diagnostics/FileVersionInfo/ProductMinorPart/source.cs | Convert WinForms snippet to console/top-level and modernize path handling. |
| snippets/csharp/System.Diagnostics/FileVersionInfo/ProductMinorPart/Project.csproj | Switch project to Exe/net10.0; remove unnecessary PerformanceCounter package. |
| snippets/csharp/System.Diagnostics/FileVersionInfo/ProductMajorPart/source.cs | Convert WinForms snippet to console/top-level and modernize path handling. |
| snippets/csharp/System.Diagnostics/FileVersionInfo/ProductMajorPart/Project.csproj | Switch project to Exe/net10.0; remove unnecessary PerformanceCounter package. |
| snippets/csharp/System.Diagnostics/FileVersionInfo/ProductBuildPart/source.cs | Convert WinForms snippet to console/top-level and modernize path handling. |
| snippets/csharp/System.Diagnostics/FileVersionInfo/ProductBuildPart/Project.csproj | Switch project to Exe/net10.0; remove unnecessary PerformanceCounter package. |
| snippets/csharp/System.Diagnostics/FileVersionInfo/PrivateBuild/source.cs | Convert WinForms snippet to console/top-level and modernize path handling. |
| snippets/csharp/System.Diagnostics/FileVersionInfo/PrivateBuild/Project.csproj | Switch project to Exe/net10.0; remove unnecessary PerformanceCounter package. |
| snippets/csharp/System.Diagnostics/FileVersionInfo/Overview/source.cs | Convert to console/top-level and modernize formatting. |
| snippets/csharp/System.Diagnostics/FileVersionInfo/Overview/Project.csproj | Switch project to Exe/net10.0. |
| snippets/csharp/System.Diagnostics/FileVersionInfo/OriginalFilename/source.cs | Convert WinForms snippet to console/top-level and modernize path handling. |
| snippets/csharp/System.Diagnostics/FileVersionInfo/OriginalFilename/Project.csproj | Switch project to Exe/net10.0; remove unnecessary PerformanceCounter package. |
| snippets/csharp/System.Diagnostics/FileVersionInfo/LegalTrademarks/source.cs | Convert WinForms snippet to console/top-level and modernize path handling. |
| snippets/csharp/System.Diagnostics/FileVersionInfo/LegalTrademarks/Project.csproj | Switch project to Exe/net10.0; remove unnecessary PerformanceCounter package. |
| snippets/csharp/System.Diagnostics/FileVersionInfo/LegalCopyright/source.cs | Convert WinForms snippet to console/top-level and modernize path handling. |
| snippets/csharp/System.Diagnostics/FileVersionInfo/LegalCopyright/Project.csproj | Switch project to Exe/net10.0; remove unnecessary PerformanceCounter package. |
| snippets/csharp/System.Diagnostics/FileVersionInfo/IsSpecialBuild/source.cs | Convert WinForms snippet to console/top-level and modernize path handling. |
| snippets/csharp/System.Diagnostics/FileVersionInfo/IsSpecialBuild/Project.csproj | Switch project to Exe/net10.0; remove unnecessary PerformanceCounter package. |
| snippets/csharp/System.Diagnostics/FileVersionInfo/IsPrivateBuild/source.cs | Convert WinForms snippet to console/top-level and modernize path handling. |
| snippets/csharp/System.Diagnostics/FileVersionInfo/IsPrivateBuild/Project.csproj | Switch project to Exe/net10.0; remove unnecessary PerformanceCounter package. |
| snippets/csharp/System.Diagnostics/FileVersionInfo/IsPreRelease/source.cs | Convert WinForms snippet to console/top-level and modernize path handling. |
| snippets/csharp/System.Diagnostics/FileVersionInfo/IsPreRelease/Project.csproj | Switch project to Exe/net10.0; remove unnecessary PerformanceCounter package. |
| snippets/csharp/System.Diagnostics/FileVersionInfo/IsPatched/source.cs | Convert WinForms snippet to console/top-level and modernize path handling. |
| snippets/csharp/System.Diagnostics/FileVersionInfo/IsPatched/Project.csproj | Switch project to Exe/net10.0; remove unnecessary PerformanceCounter package. |
| snippets/csharp/System.Diagnostics/FileVersionInfo/IsDebug/source.cs | Convert WinForms snippet to console/top-level and modernize path handling. |
| snippets/csharp/System.Diagnostics/FileVersionInfo/IsDebug/Project.csproj | Switch project to Exe/net10.0; remove unnecessary PerformanceCounter package. |
| snippets/csharp/System.Diagnostics/FileVersionInfo/InternalName/source.cs | Convert WinForms snippet to console/top-level and modernize path handling. |
| snippets/csharp/System.Diagnostics/FileVersionInfo/InternalName/Project.csproj | Switch project to Exe/net10.0; remove unnecessary PerformanceCounter package. |
| snippets/csharp/System.Diagnostics/FileVersionInfo/FilePrivatePart/source.cs | Convert WinForms snippet to console/top-level and modernize path handling. |
| snippets/csharp/System.Diagnostics/FileVersionInfo/FilePrivatePart/Project.csproj | Switch project to Exe/net10.0; remove unnecessary PerformanceCounter package. |
| snippets/csharp/System.Diagnostics/FileVersionInfo/FileName/source.cs | Convert WinForms snippet to console/top-level and modernize path handling. |
| snippets/csharp/System.Diagnostics/FileVersionInfo/FileName/Project.csproj | Switch project to Exe/net10.0; remove unnecessary PerformanceCounter package. |
| snippets/csharp/System.Diagnostics/FileVersionInfo/FileMinorPart/source.cs | Convert WinForms snippet to console/top-level and modernize path handling. |
| snippets/csharp/System.Diagnostics/FileVersionInfo/FileMinorPart/Project.csproj | Switch project to Exe/net10.0; remove unnecessary PerformanceCounter package. |
| snippets/csharp/System.Diagnostics/FileVersionInfo/FileMajorPart/source.cs | Convert WinForms snippet to console/top-level and modernize path handling. |
| snippets/csharp/System.Diagnostics/FileVersionInfo/FileMajorPart/Project.csproj | Switch project to Exe/net10.0; remove unnecessary PerformanceCounter package. |
| snippets/csharp/System.Diagnostics/FileVersionInfo/FileDescription/source.cs | Convert WinForms snippet to console/top-level and modernize path handling. |
| snippets/csharp/System.Diagnostics/FileVersionInfo/FileDescription/Project.csproj | Switch project to Exe/net10.0; remove unnecessary PerformanceCounter package. |
| snippets/csharp/System.Diagnostics/FileVersionInfo/FileBuildPart/source.cs | Convert WinForms snippet to console/top-level and modernize path handling. |
| snippets/csharp/System.Diagnostics/FileVersionInfo/FileBuildPart/Project.csproj | Switch project to Exe/net10.0; remove unnecessary PerformanceCounter package. |
| snippets/csharp/System.Diagnostics/FileVersionInfo/CompanyName/source.cs | Convert WinForms snippet to console/top-level and modernize path handling. |
| snippets/csharp/System.Diagnostics/FileVersionInfo/CompanyName/Project.csproj | Switch project to Exe/net10.0; remove unnecessary PerformanceCounter package. |
| snippets/csharp/System.Diagnostics/FileVersionInfo/Comments/source.cs | Convert WinForms snippet to console/top-level and modernize path handling. |
| snippets/csharp/System.Diagnostics/FileVersionInfo/Comments/Project.csproj | Switch project to Exe/net10.0; remove unnecessary PerformanceCounter package. |
| snippets/csharp/System.Diagnostics/EventSourceCreationData/Overview/source.cs | Modernize to file-scoped namespace, improve flow and messaging, and add file validation. |
| snippets/csharp/System.Diagnostics/EventSourceCreationData/Overview/Project.csproj | Switch to Exe/net10.0 and use EventLog package reference. |
| snippets/csharp/System.Diagnostics/EventLogTraceListener/Overview/source.cs | Modernize construction/disposal with using declaration. |
| snippets/csharp/System.Diagnostics/EventLogTraceListener/Overview/Project.csproj | Minor whitespace normalization; keep EventLog dependency. |
| snippets/csharp/System.Diagnostics/EventLogEntryType/Overview/Project.csproj | Switch to Exe/net10.0 and use EventLog package reference. |
| snippets/csharp/System.Diagnostics/EventLogEntryType/Overview/eventlogentrytype_6.cs | Modernize to top-level try/catch and updated formatting. |
| snippets/csharp/System.Diagnostics/EventLogEntryCollection/Overview/Project.csproj | Switch to Exe/net10.0 and use EventLog package reference. |
| snippets/csharp/System.Diagnostics/EventLogEntryCollection/Overview/eventlogentry_copyto.cs | Modernize to top-level try/catch and add disposal patterns. |
| snippets/csharp/System.Diagnostics/EventLogEntryCollection/Count/Project.csproj | Switch to Exe/net10.0 and use EventLog package reference. |
| snippets/csharp/System.Diagnostics/EventLogEntryCollection/Count/eventlogentry_item.cs | Modernize to top-level try/catch and add disposal patterns. |
| snippets/csharp/System.Diagnostics/EventLogEntry/Overview/Project.csproj | Switch to Exe/net10.0 and use EventLog package reference. |
| snippets/csharp/System.Diagnostics/EventLogEntry/Overview/eventlogentry_source.cs | Modernize to top-level statements and switch expression. |
| snippets/csharp/System.Diagnostics/EventLog/WriteEntry/source2.cs | Convert Main → Run and modernize formatting. |
| snippets/csharp/System.Diagnostics/EventLog/WriteEntry/source1.cs | Convert Main → Run, add disposal, and modernize formatting. |
| snippets/csharp/System.Diagnostics/EventLog/WriteEntry/source.cs | Convert Main → Run and modernize formatting. |
| snippets/csharp/System.Diagnostics/EventLog/WriteEntry/Project.csproj | Normalize project settings for consolidated Program entry point. |
| snippets/csharp/System.Diagnostics/EventLog/WriteEntry/Program.cs | Add consolidated entry point sequencing multiple WriteEntry samples. |
| snippets/csharp/System.Diagnostics/EventLog/WriteEntry/eventlog_writeentry_5.cs | Convert Main → Run and modernize formatting/initializers. |
| snippets/csharp/System.Diagnostics/EventLog/WriteEntry/eventlog_writeentry_4.cs | Convert Main → Run and modernize formatting. |
| snippets/csharp/System.Diagnostics/EventLog/WriteEntry/eventlog_writeentry_1_3.cs | Convert Main → Run, add disposal, and modernize loops/formatting. |
| snippets/csharp/System.Diagnostics/EventLog/Source/source.cs | Modernize to top-level and add disposal while preserving API usage. |
| snippets/csharp/System.Diagnostics/EventLog/Source/Project.csproj | Minor whitespace normalization; keep EventLog dependency. |
| snippets/csharp/System.Diagnostics/EventLog/Overview/source.cs | Modernize to top-level and add disposal while preserving API usage. |
| snippets/csharp/System.Diagnostics/EventLog/Overview/Project.csproj | Minor whitespace normalization; keep EventLog dependency. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 107 out of 110 changed files in this pull request and generated 1 comment.
Suppressed comments (2)
Previously missed (2) — in code that hasn't changed since the last review.
snippets/csharp/System.Diagnostics/PerformanceCounterCategory/Create/program.cs:254
- The new executable entry point invokes only
PerfCounter1.Run, even thoughccd.cs:5was also converted fromMaintoSnippet.Run. This leaves that sample unreachable when the consolidated project is run; include every renamed entry point.
snippets/csharp/System.Diagnostics/EventLogEntryType/Overview/eventlogentrytype_6.cs:35 - Correct the spelling of “application” in this user-facing message.
"then run the applicaton again to use the new event source.");
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Summary
Modernizes the second batch of 60 C# snippets in the
System.Diagnosticsnamespace so they use current C# syntax while preserving the documented APIs and runtime behavior.Updates 46 .NET 10 snippet projects and adds four consolidation entry points for directories containing multiple samples. All affected projects build successfully; remaining warnings are expected Windows-platform annotations for EventLog and performance-counter APIs.
Internal previews
Toggle expand/collapse
Note
This table shows the first 50 preview links (sorted alphabetically by file path) found in the OPS build report. For the full list, select OpenPublishing.Build Details within checks.
Build report