Contents
.NET 6 Web App¶
These steps describe how to install and configure KissLog for a .NET 6 Web 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.AspNetCore;
using KissLog.CloudListeners.Auth;
using KissLog.CloudListeners.RequestLogsListener;
using KissLog.Formatters;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddLogging(provider =>
{
provider
.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 });
};
});
});
builder.Services.AddHttpContextAccessor();
builder.Services.AddRazorPages();
builder.Services.AddControllers();
var app = builder.Build();
app.UseStaticFiles();
app.UseRouting();
app.UseAuthorization();
app.MapRazorPages();
app.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
app.UseKissLogMiddleware(options => {
options.Listeners.Add(new RequestLogsApiListener(new Application(
builder.Configuration["KissLog.OrganizationId"],
builder.Configuration["KissLog.ApplicationId"])
)
{
ApiUrl = builder.Configuration["KissLog.ApiUrl"]
});
});
app.Run();
Write logs:
using Microsoft.AspNetCore.Mvc;
namespace dotnet_WebApplication.Controllers
{
public class HomeController : Controller
{
private readonly ILogger<HomeController> _logger;
public HomeController(ILogger<HomeController> logger)
{
_logger = logger;
}
public IActionResult Index()
{
_logger.LogDebug("Hello world from dotnet 6!");
return View();
}
}
}
For technical support, questions or any feedback, please feel free to send us a message and we will get back to you.