Console applications

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

  1. Install NuGet Packages

PM> Install-Package KissLog
PM> Install-Package KissLog.Apis.v1
  1. Update Program.cs

Register KissLog.net cloud listener.

Replace OrganizationID and ApplicationID with Api Key values from the application configuration page.

Make sure you specify UseAsync = false (line 21).

 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
using KissLog;
using KissLog.Apis.v1.Listeners;

namespace ConsoleApp_sample
{
    class Program
    {
        static void Main(string[] args)
        {
            ConfigureKissLog();
        }

        static void ConfigureKissLog()
        {
            // replace the values
            string organizationId = "OrganizationID";
            string applicationId = "ApplicationID";

            ILogListener listener = new KissLogApiListener(new KissLog.Apis.v1.Auth.Application(organizationId, applicationId))
            {
                UseAsync = false
            };

            KissLogConfiguration.Listeners.Add(listener);
        }
    }
}
  1. Use the ILogger

We log the Foo() method by using a try-catch-finally block to simulate the BEGIN and the END of the action.

 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
using KissLog;
using KissLog.Apis.v1.Listeners;

namespace ConsoleApp_sample
{
    class Program
    {
        static void Main(string[] args)
        {
            ConfigureKissLog();

            Foo();
        }

        private static void Foo()
        {
            ILogger logger = new Logger(url: "Foo");

            try
            {
                logger.Info("Foo started");

                // execute foo
            }
            catch(Exception ex)
            {
                logger.Error(ex);
                throw;
            }
            finally
            {
                Logger.NotifyListeners(logger);
            }
        }
    }
}

Testing

To test the KissLog configuration, run the Console application. The Foo() request should be visible on KissLog.net.

Foo() details

Foo() details

Foo() logs

Foo() logs