I'm writing a Visual Studio extension using MEF an I'm wondering how to add logging to the code. When writing a VsPackage one could use the "Action Log" like shown in MSDN. But this isn't possible in a MEF extension.
How should I do my logging? Is it even possible to write to the VS access log using a MEF extension? Should I do my own logging using nlog or similar.
You can still use the IVsActivityLog
. The only thing that changes is the way you get access to the IVsActivityLog
instance. Instead of this:
IVsActivityLog log = GetService(typeof(SVsActivityLog)) as IVsActivityLog;
You would first [Import]
the SVsServiceProvider
:
[Import] internal SVsServiceProvider ServiceProvider = null;
Then you can call IServiceProvider.GetService
:
IVsActivityLog log = ServiceProvider.GetService(typeof(SVsActivityLog)) as IVsActivityLog;