Console App (.NET Framework)

These steps describe how to install and configure KissLog for a .NET Framework Console application.

A full working example can be found here.

By following the install instructions, you will:

  • create a “main” logger instance and use it throughout the Main(string[] args) method execution

  • register RequestLogsApiListener listener which will save the captured data to kisslog.net

Instructions

  1. Install NuGet Packages

Package Manager Console
PM> Install-Package KissLog
PM> Install-Package KissLog.CloudListeners
  1. Update App.config

App.config
<configuration>
    <appSettings>
        <add key="KissLog.OrganizationId" value="_OrganizationId_" />
        <add key="KissLog.ApplicationId" value="_ApplicationId_" />
        <add key="KissLog.ApiUrl" value="https://api.kisslog.net" />
    </appSettings>
</configuration>
  1. Update Program.cs

Program.cs
 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
33
34
35
36
37
38
39
40
41
using KissLog;
using KissLog.CloudListeners.Auth;
using KissLog.CloudListeners.RequestLogsListener;

namespace ConsoleApp_NetFramework
{
    class Program
    {
        static void Main(string[] args)
        {
            Logger.SetFactory(new LoggerFactory(new Logger(url: "ConsoleApp/Main")));

            ConfigureKissLog();

            IKLogger logger = Logger.Factory.Get();

            logger.Trace("Trace log");
            logger.Debug("Debug log");
            logger.Info("Information log");

            // notify the listeners
            var loggers = Logger.Factory.GetAll();
            Logger.NotifyListeners(loggers);
        }

        static void ConfigureKissLog()
        {
            KissLogConfiguration.InternalLog = (message) =>
            {
                Debug.WriteLine(message);
            };

            KissLogConfiguration.Listeners
                .Add(new RequestLogsApiListener(new Application(ConfigurationManager.AppSettings["KissLog.OrganizationId"], ConfigurationManager.AppSettings["KissLog.ApplicationId"]))
                {
                    ApiUrl = ConfigurationManager.AppSettings["KissLog.ApiUrl"],
                    UseAsync = false
                });
        }
    }
}
Console App (.NET Framework)