Skip to content

Install WindowsApp

catalin.gavan edited this page Jul 5, 2019 · 3 revisions

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

Steps

1. Install NuGet Packages

Install NuGet package KissLog

PM> Install-Package KissLog

Install NuGet package KissLog.Apis.v1

PM> Install-Package KissLog.Apis.v1

2. Update Program.cs

Register the KissLog cloud listener at application startup.

Please make sure you update the KissLogApiListener.UseAsync property to false;

using KissLog;
using KissLog.Apis.v1.Listeners;

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

        static void ConfigureKissLog()
        {
            // replace `Organization ID` and `Application ID` with corresponding values from KissLog account page
            KissLogConfiguration.Listeners.Add(new KissLogApiListener(new KissLog.Apis.v1.Auth.Application(
                "Organization ID",
                "Application ID")
            )
            {
                UseAsync = false
            });
        }
    }
}

3. Use the ILogger

For Windows / Console applications, the ILogger needs to be created and flushed manually.

This can be achieved by using a try-catch-finally block.

using KissLog;
using KissLog.Apis.v1.Listeners;

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

            Foo();
        }

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

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

                // execute foo
            }
            catch(Exception ex)
            {
                logger.Error(ex);
                throw;
            }
            finally
            {
                logger.Info("Foo completed");

                // persist the logs
                Logger.NotifyListeners(logger);
            }
        }
    }
}
You can’t perform that action at this time.