Logging

Integrating via

The eKasa library connects to logging through the Microsoft.Extensions.Logging.Abstractions abstraction. The Client class accepts an ILoggerFactory instance, so the library does not dictate a logging tool: you use the one your application already has.

Supported tools

You can use any logging tool that provides an ILoggerFactory, for example:

Tool Connection to ILoggerFactory
Serilog serilog-extensions-logging
log4net Microsoft.Extensions.Logging.Log4Net.AspNetCore
Seq Seq.Extensions.Logging

Example with Serilog

  1. Install the NuGet packages Serilog.Extensions.Logging and Serilog.Sinks.Console.
  2. Create a Serilog logger Set the level of detail of logged messages and the console output.
  3. Wrap it in an ILoggerFactory With the SerilogLoggerFactory class.
  4. Pass it to the client To the Client(configuration, loggerFactory) constructor, see Library instantiation.
using Microsoft.Extensions.Logging;
using NineDigit.eKasa;
using Serilog;
using Serilog.Extensions.Logging;

namespace SerilogExampleApp
{
    class SerilogLoggerExample
    {
        public void Demo(ClientConfiguration configuration)
        {
            // The Client class accepts an ILoggerFactory instance.
            // Thanks to this abstraction, you can use your favourite logging tool.

            // This example uses Serilog with the NuGet packages:
            // - Serilog.Extensions.Logging
            // - Serilog.Sinks.Console

            Serilog.ILogger serilogLogger = new LoggerConfiguration()
                .MinimumLevel.Debug() // level of detail of logged messages
                .WriteTo.Console()
                .CreateLogger();

            // create a universal Microsoft.Extensions.Logging.ILoggerFactory instance
            ILoggerFactory loggerFactory = new SerilogLoggerFactory(serilogLogger);

            // test the logger
            loggerFactory.CreateLogger(nameof(SerilogLoggerExample)).LogDebug("Hello from SerilogExampleApp!");

            // create the entry point of the whole solution, the Client instance
            Client client = new NineDigit.eKasa.Client(configuration, loggerFactory);
        }
    }
}

More Serilog configuration options are in the Serilog documentation.

Next steps

Esc

↑↓ selectEnter openEsc close

Chýba vám niečo v dokumentácii?

Napíšte nám, s čím potrebujete pomôcť. Ozveme sa do pár hodín.

Údaje použijeme len na odpoveď. Viac v ochrane osobných údajov.