Logging

Logging in TSLab

When executing a script, you can write your own logs. There is an IContext.Log method for this.

"Hello world" to the log.

using TSLab.Script;
using TSLab.Script.Handlers;

namespace MyLib
{
    public class ExampleLog : IExternalScript
    {
        public void Execute(IContext ctx, ISecurity sec)
        {
            ctx.Log("Hello world", MessageType.Info);
        }
    }
}

MessageType.Info - it is a message type, it can be Debug, Info, Warning, Error.

This message will be displayed in the general program log (tslab.log file):

14:00:01.00[10]INFO :100:Info:Script::Hello world

You can also optionally display a message in the program window:

ctx.Log("Hello world", MessageType.Info, true);

To display additional information by passing a list of values in the dictionary:

var args = new Dictionary<string, object> { { "agent", ctx.Runtime.TradeName } };
ctx.Log("Hello world", MessageType.Info, true, args);

The log file (tslab.log) will display:

14:00:02.00[10]INFO :100:Info:Script:(agent:ExampleLog):Hello world

Last updated