I have written a simple MS Word AddIn in Visual Studio 2013, and I would like to be able to log events, preferbly to the Windows Event Viewer. It seems that I will run into permission issues if I try to create a new event source for my application. I am looking for the simplest approach to enable logging events from my VSTO that does not violate good programming guidelines.
Option 1: Use the VSTO 4.0 source
I see from the MSDN documentation on Event Logging for Office Solutions that:
You can use the event viewer in Windows to see exception messages that are captured by the Visual Studio Tools for Office runtime when you install or uninstall Office solutions. You can use these messages from the event logger to resolve installation and deployment problems.
These events are logged using the VSTO 4.0
source. Can I use the VSTO 4.0
source to log errors from my own AddIn, or would this considered bad practice?
Edit: From Eugene Astafiev's answer and what I've read elsewhere it seems this would be a bad approach since the VSTO 4.0
source is only supposed to deal with the management of the AddIns, not the AddIns themselves. Answers to other questions have also advised against using "generic" sources.
Option 2: Create a bootstrap app to be included in the installer
As an alternative, I could include a simple bootstrap application which creates the source during installation, but I can't see how to add my own prerequisites using the Install Settings under Properties > Publish in Visual Studio. Can it be done? Is there another way to do it? I would prefer not to have to create an InstallShield Windows Installer since in every other respect the installer created by default works well for my purposes. It seems like overkill to create a full installer just to get event logging working.
Edit: So far, it seems that there is no "easy" way to do this, although it is not too complicated to create an installer by following the linked instructions.
Option 3: Use a logging framework and log to a file
A third option would be to use log4net or similar logging framework and configure a File Appender to log to a file.
Initially I was not very keen to implement file logging, because a) My application would not be logging very frequently, and b) I wanted to avoid having log files scattered in various locations that are hard to find.
Edit: This is the option I have taken so far, since it required the least configuration and is adaptable if my logging requirements change in the future.