.Net Core

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

  1. Install NuGet Package

PM> Install-Package KissLog.AspNetCore
  1. Update appSettings.json

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

appsettings.json
{
    "KissLog.OrganizationId": "OrganizationID",
    "KissLog.ApplicationId": "ApplicationID"
}
  1. Update Startup.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
using KissLog.Apis.v1.Listeners;
using KissLog.AspNetCore;
using KissLog.Listeners;

namespace KissLog.Samples.AspNetCore
{
    public class Startup
    {
        public Startup(IConfiguration configuration)
        {
            Configuration = configuration;
        }

        public IConfiguration Configuration { get; }

        public void ConfigureServices(IServiceCollection services)
        {
            services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
            services.AddScoped<ILogger>((context) =>
            {
                return Logger.Factory.Get();
            });

            services.AddSession();

            services.AddMvc();
        }

        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseStaticFiles();

            app.UseSession();

            // make sure it is added after app.UseStaticFiles() and app.UseSession(), and before app.UseMvc()
            app.UseKissLogMiddleware(options => {
                options.Listeners.Add(new KissLogApiListener(new KissLog.Apis.v1.Auth.Application(
                    Configuration["KissLog.OrganizationId"],
                    Configuration["KissLog.ApplicationId"])
                ));
            });

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });
        }
    }
}
  1. Use the ILogger

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
using KissLog;

namespace KissLog.Samples.AspNetCore.Controllers
{
    public class HomeController : Controller
    {
        private readonly ILogger _logger;
        public HomeController(ILogger logger)
        {
            _logger = logger;
        }

        public IActionResult Index()
        {
            _logger.Debug("Hello world from AspNetCore!");

            return View();
        }
    }
}

Testing

To test the KissLog configuration, trigger a request on /Home/Index. The request should be visible on KissLog.net.

Request details

Request details

Request logs

Request logs