Logging capabilities in SwEx framework for SOLIDWORKS add-ins
All base SwEx modules inherit the IModule interface which provides an access to ILogger instance allowing to log custom messages and exception from the module.
The following modules provide logger:
Additional options can be specified by decorating the module class via LoggerOptionsAttribute
using CodeStack.SwEx.AddIn; using CodeStack.SwEx.AddIn.Attributes; using CodeStack.SwEx.Common.Attributes; using System; using System.Runtime.InteropServices; namespace CodeStack.SwEx { [LoggerOptions(true, LOGGER_NAME)] [AutoRegister] [ComVisible(true), Guid("CD7C743A-3C82-4A4A-B557-BBD6228CE2C8")] public class LogAddIn : SwAddInEx { internal const string LOGGER_NAME = "MyAddInLog"; public override bool OnConnect() { try { Logger.Log("Loading add-in..."); //TODO: implement connection return true; } catch (Exception ex) { Logger.Log(ex); throw; } } } }
Specified logger name will be appended to the SwEx module name (e.g. SwEx.AddIn.MyAddInLog or SwEx.MacroFeature.MyAddInLog or SwEx.PMPage.MyAddInLog).
Log messages are output into the output as setup via LoggerOptionsAttribute attribute. Currently only debug trace logger is supported. Refer Troubleshooting article for the instructions of how to capture debug trace messages.