Add Roslyn analyzer for non-contextual logger usage in orchestrations (DURABLE0010)#553
Conversation
Co-authored-by: YunchuWang <12449837+YunchuWang@users.noreply.github.com>
…ate diagnostics Co-authored-by: YunchuWang <12449837+YunchuWang@users.noreply.github.com>
Co-authored-by: YunchuWang <12449837+YunchuWang@users.noreply.github.com>
|
@copilot resolve conflict and DURABLE0009 already exists |
I've resolved the merge conflict by rebasing onto commit 2adacc2 (v1.18.1). The conflict was in DURABLE0009 was not previously used - I originally assigned this ID for the LoggerOrchestrationAnalyzer. All 104 analyzer tests pass after the rebase (commits c7efa48, 44972c9, 788f41b, e163846). |
There was a problem hiding this comment.
Pull request overview
This PR adds a new Roslyn analyzer (DURABLE0010) to detect non-contextual logger usage in orchestration methods. The analyzer warns developers when they use injected ILogger or ILogger<T> instances instead of replay-safe loggers created via context.CreateReplaySafeLogger(), helping prevent unexpected behavior during orchestration replays.
Key changes:
- New analyzer detects ILogger parameters, field references, and property references in orchestrations
- Supports Durable Functions, TaskOrchestrator, and Func-based orchestrator patterns
- Comprehensive test coverage with 14 new test cases covering various scenarios
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| src/Analyzers/Orchestration/LoggerOrchestrationAnalyzer.cs | New analyzer implementation that detects non-contextual ILogger usage in orchestration methods |
| src/Analyzers/KnownTypeSymbols.Net.cs | Adds ILogger type symbol lookup support for the analyzer |
| src/Analyzers/Resources.resx | Adds localized title and message format for the new DURABLE0010 diagnostic |
| src/Analyzers/AnalyzerReleases.Unshipped.md | Documents the new DURABLE0010 analyzer rule |
| test/Analyzers.Tests/Orchestration/LoggerOrchestrationAnalyzerTests.cs | Comprehensive test suite with 14 test cases covering all orchestration patterns |
| test/Analyzers.Tests/Wrapper.cs | Adds Microsoft.Extensions.Logging using statement to support logger tests |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
|
@copilot update pr description to follow .github/PULL_REQUEST_TEMPLATE.md |
Co-authored-by: YunchuWang <12449837+YunchuWang@users.noreply.github.com>
Updated the PR description to follow the |
Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com>
|
@YunchuWang Unfortunately I hit an unexpected error while processing your comment. I've automatically reported this to GitHub. You can ask me to try again later by mentioning me in a new comment. If you want to contact GitHub about this error, please mention the following identifier so they can better serve you: Sorry for the inconvenience! |




Summary
What changed?
ILoggerorILogger<T>instead of replay-safe loggers created viacontext.CreateReplaySafeLogger()Why is this change needed?
Issues / work items
Project checklist
AI-assisted code disclosure (required)
Was an AI tool used? (select one)
If AI was used:
src/Analyzers/Orchestration/LoggerOrchestrationAnalyzer.cs- Complete implementationsrc/Analyzers/KnownTypeSymbols.Net.cs- Added ILogger symbolsrc/Analyzers/Resources.resx- Added diagnostic messagessrc/Analyzers/AnalyzerReleases.Unshipped.md- Added DURABLE0010 entrytest/Analyzers.Tests/Orchestration/LoggerOrchestrationAnalyzerTests.cs- Complete test suitetest/Analyzers.Tests/Wrapper.cs- Added ILogger using statementAI verification (required if AI was used):
Testing
Automated tests
Manual validation (only if runtime/behavior changed)
Notes for reviewers
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.