Skip to main content

Logging

Logging in a MoBro plugin is as simple as just injecting a Microsoft.Extensions.Logging.ILogger via the plugins constructor (see In depth: Using services):

Plugin.cs
using Microsoft.Extensions.Logging;

public class Plugin : IMoBroPlugin
{
private readonly ILogger _logger;

public Plugin(ILogger logger)
{
_logger = logger;
}

public void Init()
{
_logger.LogInformation("Initializing plugin");
}
}

The logger instance passed to the plugin is already properly configured and integrated into the logging structure of the MoBro data service.

Local testing

When a plugin is started as a console application for local testing like described in In depth: Testing - Start locally, the injected logger instance will only log to the console by default.
The default log level is set to DEBUG.

A custom logger can be used by passing it to the MoBroPluginBuilder when creating the plugin:

Program.cs
// create custom logger
var logger = ...

// create and start the plugin locally with a custom logger
var plugin = MoBroPluginBuilder
.Create<Plugin.Example.Plugin>()
.WithSetting("update_frequency", "1")
.WithLogger(logger)
.Build();

// prevent the program from exiting immediately
Console.ReadLine();

Instead of passing a custom logger, the MoBroPluginBuilder also allows to just change the log level:

var plugin = MoBroPluginBuilder
.Create<Plugin.Example.Plugin>()
.WithLogLevel(LogEventLevel.Warning)
.Build();

Installed to MoBro

When a plugin is installed to MoBro, the default log level is set to Information and the log outputs are:

  • forwarded to the MoBro data service and included in the service log for debug purposes
  • additionally written to a separate plugin-specific log file in the plugins' installation directory
    • rolls over every day or at 10MB file size
    • retains the last 14 files

Whenever a debug.zip is generated in MoBro, the full log history of all plugins is automatically included.

The current log file of an installed plugin can also be accessed via the Rest API of the MoBro data service: localhost:42069/api/logs/plugins/[plugin_name]
(Replace the [plugin_name] with the unique plugin name as configured in the mobro_plugin_config.json)