OpenTap logging in modules

Hallo,

As of recent we have started to update our plugins, and we run into an issue regarding logging.
We prefer to keep our libraries/modules as general as we can. But in the past, this resulted in us not using the logging provided by OpenTap. Needless to say, this made is sometimes difficult to troubleshoot.

We plan to pass a logging class to the modules via an interface.
However we run into the following: In order to make use of the Resource.Log methods we make a class like this:

private class Log_adapter : Instrument, ILogger
{
public void Debug(string msg) => Log.Debug(msg);
public void Info(string msg) => Log.Info(msg);
public void Warning(string msg) => Log.Warning(msg);
public void Error(string msg) => Log.Error(msg);
}

We inherit from an instrument (or teststep) in order to get access to the Resource.Log. But it feels a bit like we mis-use the instrument here. What would be a nicer solution for this? If there is one.

Thanks in advance.

PS. a Happy new year!

Hi @marc_vd_klooster,

You can use Log.CreateSource("nameOfMyLogSource") to create a OpenTap.TraceSource object. Then you won’t need your class to inherit from Instrument.

for example:

public class MyClass
{
    TraceSource log = Log.CreateSource("Module1Log");

   ///...
  void MyFunction()
  {
     log.Debug("Something happened");
   } 

}

Hi @rolf_madsen ,

Thanks, this is exactly what I was looking for.