Logs output

KissLog saves the logs to multiple output locations by using log listeners.

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

KissLog.net listener

RequestLogsApiListener saves the logs to kisslog.net (or KissLog on-premises).

RequestLogsApiListener

RequestLogsApiListener output

Usage
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
using KissLog;
using KissLog.CloudListeners.Auth;
using KissLog.CloudListeners.RequestLogsListener;

namespace MyApplication
{
    public class MvcApplication : System.Web.HttpApplication
    {
        // [...]

        private void RegisterKissLogListeners()
        {
            ILogListener listener = new RequestLogsApiListener(new Application("_OrganizationId_", "_ApplicationId_"))
            {
                ApiUrl = "https://api.kisslog.net"
            };

            // register KissLog.net cloud listener
            KissLogConfiguration.Listeners.Add(listener);
        }
    }
}

Text file listener

LocalTextFileListener saves the logs on local text files.

LocalTextFileListener

LocalTextFileListener output

Usage
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
using KissLog;

namespace MyApplication
{
    public class MvcApplication : System.Web.HttpApplication
    {
        // [...]

        private void RegisterKissLogListeners()
        {
            ILogListener listener = new LocalTextFileListener(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Logs"))
            {
                FlushTrigger = FlushTrigger.OnMessage
            };

            // register local text file listener
            KissLogConfiguration.Listeners.Add(listener);
        }
    }
}

NLog listener

NLogTargetListener saves the logs created with KissLog to all the NLog targets defined in NLog.config.

This is useful when you want to use save the logs to both kisslog.net and NLog text-files.

NLog output

NLog output

NLog.config

NLog.config

Registering NLog listener
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
using KissLog;

namespace MyApplication
{
    public class MvcApplication : System.Web.HttpApplication
    {
        // [...]

        private void RegisterKissLogListeners()
        {
            // register NLog listener
            KissLogConfiguration.Listeners.Add(new NLogTargetListener());

            // optionally, we register the KissLog.net cloud listener
            KissLogConfiguration.Listeners.Add(new RequestLogsApiListener(new Application("_OrganizationId_", "_ApplicationId_"))
            {
                ApiUrl = "https://api.kisslog.net"
            });
        }
    }
}

Custom listeners

Custom log listeners can be created by implementing the ILogListener interface.

Creating custom log listener:
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
public class DebugOutputListener : ILogListener
{
    public int MinimumResponseHttpStatusCode { get; set; } = 0;
    public LogLevel MinimumLogMessageLevel { get; set; } = LogLevel.Trace;
    public LogListenerParser Parser { get; set; } = new LogListenerParser();

    public void OnBeginRequest(HttpRequest httpRequest, ILogger logger)
    {
        string text = string.Format(">>>>>> {0} {1}", httpRequest.HttpMethod, httpRequest.Url.PathAndQuery);

        Debug.WriteLine(text);
    }

    public void OnMessage(LogMessage message, ILogger logger)
    {
        string text = string.Format(">>>>>> {0} {1}", message.LogLevel, message.Message);

        Debug.WriteLine(text);
    }

    public void OnFlush(FlushLogArgs args, ILogger logger)
    {
        HttpRequest request = args.WebProperties.Request;
        HttpResponse response = args.WebProperties.Response;

        int httpStatusCode = (int)response.HttpStatusCode;

        string text = string.Format(">>>>>> Completed {0}", httpStatusCode);

        Debug.WriteLine(text);
    }
}
Registering the custom DebugOutputListener:
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
using KissLog;

namespace MyApplication
{
    public class MvcApplication : System.Web.HttpApplication
    {
        // [...]

        private void RegisterKissLogListeners()
        {
            KissLogConfiguration.Listeners.Add(new DebugOutputListener());
        }
    }
}
DebugOutputListener output

DebugOutputListener output

Another custom log listener can be found on the Custom MongoDB listener example.