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
 1using KissLog;
 2using KissLog.CloudListeners.Auth;
 3using KissLog.CloudListeners.RequestLogsListener;
 4
 5namespace ConsoleApp_NetFramework
 6{
 7    class Program
 8    {
 9        static void Main(string[] args)
10        {
11            Logger.SetFactory(new LoggerFactory(new Logger(url: "ConsoleApp/Main")));
12
13            ConfigureKissLog();
14
15            IKLogger logger = Logger.Factory.Get();
16
17            logger.Trace("Trace log");
18            logger.Debug("Debug log");
19            logger.Info("Information log");
20
21            // notify the listeners
22            var loggers = Logger.Factory.GetAll();
23            Logger.NotifyListeners(loggers);
24        }
25
26        static void ConfigureKissLog()
27        {
28            KissLogConfiguration.InternalLog = (message) =>
29            {
30                Debug.WriteLine(message);
31            };
32
33            KissLogConfiguration.Listeners
34                .Add(new RequestLogsApiListener(new Application(ConfigurationManager.AppSettings["KissLog.OrganizationId"], ConfigurationManager.AppSettings["KissLog.ApplicationId"]))
35                {
36                    ApiUrl = ConfigurationManager.AppSettings["KissLog.ApiUrl"],
37                    UseAsync = false
38                });
39        }
40    }
41}
Console App (.NET Framework)