About KissLog

KissLog represents a powerful logging and monitoring solution for .NET applications.

Some of the main features of KissLog are:

  • Automatically captures and logs all the exceptions

  • Monitors all the HTTP traffic

  • Lightweight, configurable SDK

  • Centralized logging using KissLog.net cloud or on-premises integration

KissLog.net centralized logging

Why KissLog?

KissLog is a logging framework which is focused primarily on HTTP behaviour.

For each HTTP request, KissLog automatically captures all the available properties, including: User Agent, Request Headers, Form Data, Request Body, SessionId, Response Headers, Status Code, Response Body.

Log messages are grouped per each unique HTTP request, making it easy to follow the execution details.

Basic usage

::using KissLog;
using System.Collections.Generic;
using System.Web.Http;

namespace MyApp.Mvc.Controllers
{
    public class HomeController : Controller
    {
        ::private readonly ILogger _logger;
        public HomeController()
        {
            ::_logger = Logger.Factory.Get();
        }

        public ActionResult Index()
        {
            ::_logger.Debug("Hello world from .NET MVC!");

            return View();
        }
    }
}

Setup

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.

Custom log listeners can be created by implementing ILogListener interface.

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

        private void RegisterKissLogListeners()
        {
            // register KissLog.net cloud listener
            KissLogConfiguration.Listeners.Add(new RequestLogsApiListener(new Application("d625d5c8-ef47-4cd5-bf2d-6b0a1fa7fda4", "39bb675d-5c13-4bd8-9b5a-1d368da020a2"))
            {
                ApiUrl = "https://api.kisslog.net"
            });
			
            // register NLog listener
            KissLogConfiguration.Listeners.Add(new NLogTargetListener());
            
            // register MongoDB listener
            KissLogConfiguration.Listeners.Add(new MongoDbListener());
        }
    }
}

Configuration

Logging behavior can be customized by using KissLogConfiguration.Options container.

Complete list of configuration options can be found on the documentation page.

protected void Application_Start()
{
    KissLogConfiguration.Options
        .JsonSerializerSettings.Converters.Add(new StringEnumConverter());

    KissLogConfiguration.Options
        .ShouldLogResponseBody((listener, logArgs, defaultValue) =>
        {
            int responseStatusCode = (int)logArgs.WebProperties.Response.HttpStatusCode;
            return responseStatusCode >= 400;
        });

    KissLogConfiguration.Options
        .AppendExceptionDetails((Exception ex) =>
        {
            // log EntityFramework validation errors
            if (ex is DbEntityValidationException dbException)
            {
                StringBuilder sb = new StringBuilder();
                sb.AppendLine("DbEntityValidationException:");

                foreach (var error in dbException.EntityValidationErrors.SelectMany(p => p.ValidationErrors))
                {
                    string message = string.Format("Field: {0}, Error: {1}", error.PropertyName, error.ErrorMessage);
                    sb.AppendLine(message);
                }

                return sb.ToString();
            }

            return null;
        });
}