Skip to content

fix: Introduce tracing capabilities for debugging rule triggers#63

Open
mfogliatto wants to merge 1 commit into
mainfrom
fix/issue-31
Open

fix: Introduce tracing capabilities for debugging rule triggers#63
mfogliatto wants to merge 1 commit into
mainfrom
fix/issue-31

Conversation

@mfogliatto
Copy link
Copy Markdown
Owner

Summary

Introduces tracing capabilities to help debug why certain references trigger specific rules.

Changes

New files

  • src/ReferenceCop/Tracing/ITraceWriter.cs — Interface for trace output
  • src/ReferenceCop/Tracing/NullTraceWriter.cs — No-op implementation (zero overhead when disabled)
  • src/ReferenceCop/Tracing/TraceWriter.cs — Collects trace messages in memory

Modified files

  • ReferenceCopConfig.cs — Added EnableTracing config property
  • ReferenceCopConfig.xsd — Added EnableTracing schema element
  • ProjectTagViolationDetector.cs — Traces rule evaluation (match/skip/suppress/violation)
  • ProjectPathViolationDetector.cs — Traces rule evaluation (match/skip/suppress/violation)
  • AssemblyNameViolationDetector.cs — Traces rule evaluation (match/suppress/violation)
  • BuildEngineExtensions.cs — Added LogTraceMessage for MSBuild output
  • ReferenceCopTask.cs — Creates trace writer from config, flushes traces to build log
  • ReferenceCopAnalyzer.cs — Creates trace writer, flushes traces as debug diagnostics

How to use

Set <EnableTracing>true</EnableTracing> in your ReferenceCop config file. Trace messages will appear:

  • MSBuild task: as normal-importance build messages with [TRACE] prefix (visible with -v:normal or higher)
  • Roslyn analyzer: as debug diagnostics (RC9999)

Design decisions

  • Zero overhead when tracing is disabled (NullTraceWriter.IsEnabled short-circuits all string interpolation)
  • Backward compatible — all existing constructors preserved via overload chaining
  • No new dependencies

Fixes #31

Adds an ITraceWriter abstraction with NullTraceWriter (disabled) and
TraceWriter (enabled) implementations. When EnableTracing is set to true
in the ReferenceCop config, all violation detectors emit detailed trace
messages explaining rule evaluation: which rules match, which references
are evaluated, why violations are triggered or suppressed.

- MSBuild task: trace messages are flushed to the build log as normal
  importance messages with [TRACE] prefix
- Roslyn analyzer: trace messages are reported as debug diagnostics
- Performance: zero overhead when tracing is disabled (NullTraceWriter
  short-circuits via IsEnabled check)
- Backward compatible: all existing constructors preserved

Fixes #31
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.

Introduce tracing capabilities for debugging rule triggers

1 participant