Add logging to a SolidWorks add-in


I’m in the process of converting a set of VBA macros to and add-in. Some of the macros write to text files logging information on the operations the macro perform.

I was wandering if any of you guys use the same method, or some other, more advanced, one…

The main request is that the logging need to be visible in some way by both the end-user and me as an administrator…

It all depends on where you want to log to. There are dozens of logging packages on Nuget, I use log4net to log to a text file and to Coralogix so I can spot errors in my products online.

I turned this into a package for internal use, which includes an event listener that you can subscribe to to show all messages in the user interface.

1 Like

Hi Peter,
thanks for you answer. I’m still thinking in “VBA terms” and have not thought to look for dedicate package on NuGet, I will look into log4net.

Yesterday I tried a simpler approach just to have a minimal working example. I leave the code here in case someone is looking for something similar.

internal class Logger
    /// <summary>
    /// The full path to the log file
    /// </summary>
    internal string LogPath { get; set; }

    internal void WriteLog(string message)
        using (StreamWriter sw = new StreamWriter(LogPath, true))

// To write to the log
var log = new Logger();
log.LogPath = @"C:\_Export\.log\log.txt"
log.WriteLog("My message");

a video tutorial here.

It’s very basic but is a starting point.

I’m curious if others use different methodologies.