Table of Contents

Logging

You can use the built-in static ILog instance to log messages at different levels (Verbose, Debug, Information, Warning, Error, Fatal). The logs will appear in the Crosser Node local log file when the flow is running.

using static Crosser.EdgeNode.Common.Utilities.Logger.Log
namespace YourOrg.FlowModule.RandomNumberModule;

public class RandomNumberModule  : FlowModule<RandomNumberModuleSettings>
{

    public RandomNumberModule () : base(FlowModuleType.Function) {}

    protected override async Task MessageReceived(IFlowMessage message)
    {
        Logger?.Debug($"Module received message: {message}");

        try
        {
            // Log input validation
            if (!ValidateInput(message))
            {
                Logger?.Warning($"Invalid input received: {message}");
                return;
            }

            // Log processing steps
            Logger?.Debug($"Processing message with settings: {Settings}");
            
            var result = await ProcessMessage(message);
            
            Logger?.Debug($"Module produced output: {result}");
            
            await Send(result);
            
            Logger?.Information("Message processed successfully");
        }
        catch (Exception ex)
        {
            Logger?.Error(ex, $"Failed to process message");
            throw;
        }
    }

    private bool ValidateInput(IFlowMessage message)
    {
        // Add input validation logic
        // Log validation failures
        return true;
    }
}

See the ILog interface for a full list of methods

Warning

Be careful with what level you log at. You do not want to log Verbose data into higher levels such as Information.