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

KissLog.net centralized logging

Basic usage

using KissLog;

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

    public IActionResult Index()
    {
        _logger.Debug("Hello World!");

        return View();
    }
}

Setup

Register listeners

KissLog saves the logs by using ILogListener listeners.

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

protected void Application_Start()
{
    // KissLog.net cloud listener
    string organizationId = "d625d5c8-ef47-4cd5-bf2d-6b0a1fa7fda4";
    string applicationId = "39bb675d-5c13-4bd8-9b5a-1d368da020a2";
    KissLogConfiguration.Listeners.Add(new KissLogApiListener(
        new KissLog.Apis.v1.Auth.Application(organizationId, applicationId)
    ));

    // NLog listener
    KissLogConfiguration.Listeners.Add(new NLogTargetListener());

    // custom listener
    KissLogConfiguration.Listeners.Add(new MyCustomListener());
}

Configuration

KissLogConfiguration.Options provides a number of properties and runtime handlers used to customize the logs output.

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;
        });
}

Integration with other loggers

NLog

If you use NLog in your application, you can register the KissLog target, which will save all the NLog logs to KissLog.net.

PM> Install-Package KissLog.Adapters.NLog
NLog.config
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
<nlog>
    <extensions>
        <add assembly="KissLog.Adapters.NLog" />
    </extensions>
    <targets>
        <target name="kisslog" type="KissLog" layout="${message}" />
    </targets>
    <rules>
        <logger name="*" minlevel="Trace" writeTo="kisslog" />
    </rules>
</nlog>
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
using NLog;

public class HomeController : Controller
{
    private readonly ILogger _logger;
    public HomeController()
    {
        _logger = LogManager.GetCurrentClassLogger();
    }

    public ActionResult Index()
    {
        _logger.Debug("Hello world from NLog!");

        return View();
    }
}
NLog logs on KissLog.net

NLog logs on KissLog.net

log4Net

If you use log4Net in your application, you can register the KissLog appender, which will save all the log4net logs to KissLog.net.

PM> Install-Package KissLog.Adapters.log4net
log4net.config
1
2
3
4
5
6
7
8
9
<log4net>
  <root>
    <level value="ALL" />
    <appender-ref ref="KissLog" />
  </root>
  <appender name="KissLog" type="KissLog.Adapters.log4net.KissLogAppender, KissLog.Adapters.log4net">
    <layout type="log4net.Layout.SimpleLayout"></layout>
  </appender>
</log4net>
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
using log4net;

public class HomeController : Controller
{
    private readonly ILog _logger;
    public HomeController()
    {
        _logger = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
    }

    public ActionResult Index()
    {
        _logger.Debug("Hello world from log4net!");

        return View();
    }
}
log4net logs on KissLog.net

log4net logs on KissLog.net

Samples

Check the code samples for more examples of using KissLog.

Feedback

Please use the GitHub issues section to report bugs, suggestions and general feedback.

Contributing

All contributions are very welcomed: code, documentation, samples, bug reports, feature requests.

License

BSD license