Saving the logs

KissLog saves the logs using log listeners.

Log listeners are services implementing ILogListener interface and they are responsible for persisting the log events to an output location such as a file or a database storage.

Log listeners are registered at application startup using the KissLogConfiguration.Listeners configuration object.

static void Main(string[] args)
        .Add(new MongoDbLogListener("mongodb://localhost:27017"))
        .Add(new LocalTextFileListener("logs", FlushTrigger.OnFlush));

    var logger = new Logger();


Using ILogListener

ILogListener interface exposes three methods which are invoked automatically on different stages of the Logger usage.

By implementing this interface you can create any custom persistence logic.

public interface ILogListener
    ILogListenerInterceptor Interceptor { get; }

    void OnBeginRequest(HttpRequest httpRequest);
    void OnMessage(LogMessage message);
    void OnFlush(FlushLogArgs args);

OnBeginRequest() is executed when a Logger with url parameter is initialized.

OnMessage() is executed when a log message is created.

OnFlush() is executed when Logger.NotifyListeners is invoked.

static void Main(string[] args)
    var logger = new Logger(url: "Program/Main"); // <--- ILogListener.OnBeginRequest()

    logger.Debug("Hello to you");   // <--- ILogListener.OnMessage()

    Logger.NotifyListeners(logger); // <--- ILogListener.OnFlush()

For technical support, questions or any feedback, please feel free to send us a message and we will get back to you.