These steps describe how to install and configure KissLog for a ASP.NET MVC application.
A full working example can be found here.
PM> Install-Package KissLog.AspNet.Mvc
using KissLog; using KissLog.AspNet.Mvc; using KissLog.AspNet.Web; using KissLog.CloudListeners.Auth; using KissLog.CloudListeners.RequestLogsListener; using System; using System.Web.Mvc; using System.Web.Routing; namespace KissLogExample.AspNet.Mvc { public class MvcApplication : System.Web.HttpApplication { protected void Application_Start() { AreaRegistration.RegisterAllAreas(); RouteConfig.RegisterRoutes(RouteTable.Routes); GlobalFilters.Filters.Add(new KissLogWebMvcExceptionFilterAttribute()); ConfigureKissLog(); } protected void Application_Error(object sender, EventArgs e) { Exception exception = Server.GetLastError(); if (exception != null) { var logger = Logger.Factory.Get(); logger.Error(exception); if (logger.AutoFlush() == false) { Logger.NotifyListeners(logger); } } } private void ConfigureKissLog() { KissLogConfiguration.Listeners.Add(new RequestLogsApiListener(new Application( "_OrganizationId_", // Get from Application configuration page "_ApplicationId_" )) { ApiUrl = "https://api.logbee.net/" }); } public static KissLogHttpModule KissLogHttpModule = new KissLogHttpModule(); public override void Init() { base.Init(); KissLogHttpModule.Init(this); } } }
Logs can be written using KissLog.IKLogger
interface.
To receive the logger instance, use Logger.Factory.Get()
factory method.
For web applications, Logger.Factory.Get()
will return the same logger instance shared across the HTTP request.
using KissLog; using System.Collections.Generic; using System.Web.Http; namespace MyApp.Mvc.Controllers { public class HomeController : Controller { private readonly IKLogger _logger; public HomeController() { _logger = Logger.Factory.Get(); } public ActionResult Index() { _logger.Debug("Hello world from ASP.NET MVC!"); return View(); } } }
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