Custom Sinks

Sometimes you need to log exceptions to multiple places. You can achieve this using a custom class that implements the ISink interface. Each ISink in the client will have the opportunity to log the exception to the target destination. In the sample below, we provide a simple ISink implementation that logs to the console.

using LlamaLogger.Core.Interfaces;

public class ConsoleSink : ISink
{
    public bool EnableLogging { get; set; }
    public LoggingLevel MinimumLoggingLevel { get; set; } = LoggingLevel.Error;

    public bool IsBusy => false;

    public void Log(LlamaLogEntry entry)
    {
        if (!string.IsNullOrEmpty(entry.LogText))
            Console.WriteLine(entry.LogText);

        if (entry.Exception != null)
            Console.WriteLine(entry.Exception.Message);
    }
}

LlamaLoggerClient client = new LlamaLoggerClient(apikey, version);
client.AddSink(new ConsoleSink());
An error has occurred. This application may no longer respond until reloaded. Reload 🗙