Custom output

To create a custom logs output, developers will implement the ILogListener interface.

A basic example of a custom log listener can look like this:

public class MyCustomLogListener : ILogListener
{
    public int MinimumResponseHttpStatusCode { get; set; } = 0;
    public LogLevel MinimumLogMessageLevel { get; set; } = LogLevel.Trace;
    public LogListenerParser Parser { get; set; } = new LogListenerParser();

    public void OnFlush(FlushLogArgs args)
    {
        WebRequestProperties webRequest = args.WebRequestProperties;

        DateTime startDateTime = webRequest.StartDateTime;
        long durationInMs = (webRequest.EndDateTime - webRequest.StartDateTime).TotalMilliseconds;
        string userAgent = webRequest.UserAgent;
        string httpMethod = webRequest.HttpMethod;
        string absoluteUri = webRequest.AbsoluteUri;

        IEnumerable<LogMessage> logMessages = args.MessagesGroups.SelectMany(p => p.Messages).OrderBy(p => p.DateTime).ToList();

        // here goes the persistence logic
    }
}

Like all other listeners, MyCustomLogListener is registered on Application startup code.

Global.asax example:

protected void Application_Start()
{
    KissLogConfiguration.Listeners.Add(new MyCustomLogListener()
    {
        MinimumResponseHttpStatusCode = 200
    });
}

Please check MongoDb output for a complete example.


  • ILogListener - component used to persist the logs
  • FlushLogArgs - holds all the information captured by KissLog for an Http Request