A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/catalingavan/KissLog.Sdk/wiki/dotnet-ConsoleApp below:

dotnet ConsoleApp · catalingavan/KissLog.Sdk Wiki · GitHub

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

Working example and other use cases can be found on the KissLog ConsoleApp integrations page.

  1. Install NuGet Package
PM> Install-Package KissLog.AspNetCore
  1. Update Program.cs
using KissLog;
using KissLog.AspNetCore;
using KissLog.CloudListeners.Auth;
using KissLog.CloudListeners.RequestLogsListener;
using KissLog.Formatters;
 
IConfiguration configuration = new ConfigurationBuilder()
    .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
    .Build();
 
ConfigureKissLog(configuration);
 
var services = new ServiceCollection();
services.AddLogging(logging =>
{
    logging
        .AddConfiguration(configuration.GetSection("Logging"))
        .AddKissLog(options =>
        {
            options.Formatter = (FormatterArgs args) =>
            {
                if (args.Exception == null)
                    return args.DefaultValue;
 
                string exceptionStr = new ExceptionFormatter().Format(args.Exception, args.Logger);
                return string.Join(Environment.NewLine, new[] { args.DefaultValue, exceptionStr });
            };
        });
});
var serviceProvider = services.BuildServiceProvider();
 
// set a global "Logger" that will be reused throughout the application execution
Logger.SetFactory(new KissLog.LoggerFactory(new Logger(url: "ConsoleApp/Main")));
 
ILogger logger = serviceProvider.GetRequiredService<ILogger<Program>>();
 
logger.LogInformation("Hello World!");
 
var loggers = Logger.Factory.GetAll();
Logger.NotifyListeners(loggers);
 
void ConfigureKissLog(IConfiguration configuration)
{
    KissLogConfiguration.Listeners
        .Add(new RequestLogsApiListener(new Application("_OrganizationId_", "_ApplicationId_"))
        {
            ApiUrl = "https://api.logbee.net/",
            UseAsync = false
        });
}

Logs can be written using Microsoft.Extensions.Logging.ILogger<> interface.

We call Logger.NotifyListeners which will execute OnFlush() method for the registered listeners.

// [...]

Logger.SetFactory(new KissLog.LoggerFactory(new Logger(url: "ConsoleApp/Main")));

ILogger logger = serviceProvider.GetService<ILogger<Program>>();

logger.LogInformation("Hello World!");

var loggers = Logger.Factory.GetAll();
Logger.NotifyListeners(loggers);

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4