realvizu / NsDepCop

NsDepCop is a static code analysis tool that helps to enforce namespace dependency rules in C# projects. No more unplanned or unnoticed dependencies in your system.
GNU General Public License v2.0
200 stars 32 forks source link

NsDepCopDiagnosticAnalyzer should write diagnostic trace info to Visual Studio Activity Log #12

Closed realvizu closed 7 years ago

realvizu commented 7 years ago

At the moment NsDepCopDiagnosticAnalyzer writes its own diagnostic trace messages (eg. cache hits/misses) to the debug output and it works in the debug build only.

It would be better if it could be configured on the host whether diagnostic trace messages are emitted or not. In case of Visual Studio being the host the obvious mechanism for writing diagnostic trace messages would be the Visual Studio Activity Log. The problem is that NsDepCopDiagnosticAnalyzer is a DiagnosticAnalyzer descendant and not a VSPackage so I can't obtain the IVsActivityLog service from the host.

realvizu commented 7 years ago

So it's:

var serviceProvider = ServiceProvider.GlobalProvider;
var activityLog = (IVsActivityLog)serviceProvider.GetService(typeof(SVsActivityLog));
realvizu commented 7 years ago

Unfortunately activity log record description cannot be formatted with whitespaces so dumps like config content are effectively unreadable. Staying with Trace.WriteLine.