Contents
.NET 6 Console App¶
These steps describe how to install and configure KissLog for a .NET 6 Console application.
A full working example can be found here.
Instructions¶
Install NuGet Package
PM> Install-Package KissLog.AspNetCore
Update appsettings.json
{
"Logging": {
"LogLevel": {
"Default": "Trace",
"Microsoft": "Information"
}
},
"LogBee.OrganizationId": "_OrganizationId_",
"LogBee.ApplicationId": "_ApplicationId_",
"LogBee.ApiUrl": "https://api.logbee.net"
}
Update Program.cs
using KissLog;
using KissLog.AspNetCore;
using KissLog.CloudListeners.Auth;
using KissLog.CloudListeners.RequestLogsListener;
Logger.SetFactory(new KissLog.LoggerFactory(new Logger(url: "ConsoleApp/Main")));
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.Build();
ILogger logger = serviceProvider.GetRequiredService<ILogger<Program>>();
logger.LogInformation("Hello world from dotnet 6!");
var loggers = Logger.Factory.GetAll();
Logger.NotifyListeners(loggers);
void ConfigureKissLog(IConfiguration configuration)
{
KissLogConfiguration.Listeners
.Add(new RequestLogsApiListener(new Application(configuration["KissLog.OrganizationId"], configuration["KissLog.ApplicationId"]))
{
ApiUrl = configuration["KissLog.ApiUrl"],
UseAsync = false
});
}
For technical support, questions or any feedback, please feel free to send us a message and we will get back to you.