.NET Framework 4.8
LogInformant supports .NET Framework 4.8 through three popular logging libraries: Serilog, NLog, and log4net. All three work the same way — install a NuGet package, add a few lines of config, done. Pick the library your project already uses.
Which library should I use? If your project already uses one, stick with it.
Starting fresh? Serilog is the easiest to set up in code.
Option A — Serilog
1 Install NuGet packages
powershell — Package Manager Console
Install-Package Serilog Install-Package Serilog.Sinks.PeriodicBatching Install-Package LogInformant.Serilog.DotNetFramework
2 Bootstrap in Global.asax.cs
Add one block to Application_Start. This sets up the logger for your entire app:
csharp — Global.asax.cs
using Serilog;
using System.Configuration;
protected void Application_Start()
{
Log.Logger = new LoggerConfiguration()
.MinimumLevel.Information()
.WriteTo.Console()
.WriteTo.LogInformant(
apiUrl: "https://app.loginformant.com",
apiKey: ConfigurationManager.AppSettings["LogInformant:ApiKey"])
.CreateLogger();
Log.Information("Application starting up");
AreaRegistration.RegisterAllAreas();
RouteConfig.RegisterRoutes(RouteTable.Routes);
}
3 Add the API key to web.config
xml — web.config
<configuration>
<appSettings>
<add key="LogInformant:ApiKey" value="YOUR-API-KEY-HERE" />
</appSettings>
</configuration>
4 Log messages in your controllers
In .NET Framework MVC, you can use ILogger<T> if you have a DI container
(e.g., Autofac, Ninject), or use the static Log class directly:
csharp — Option 1: Static Log (no DI needed)
using Serilog;
public class OrderController : Controller
{
public ActionResult PlaceOrder(int id)
{
Log.Information("Order {OrderId} placed", id);
try
{
// your logic
return RedirectToAction("Success");
}
catch (Exception ex)
{
Log.Error(ex, "Failed to place order {OrderId}", id);
return View("Error");
}
}
}
csharp — Option 2: ILogger<T> via constructor injection
public class OrderController : Controller
{
private readonly ILogger<OrderController> _logger;
public OrderController(ILogger<OrderController> logger)
{
_logger = logger;
}
public ActionResult PlaceOrder(int id)
{
_logger.LogInformation("Order {OrderId} placed", id);
// ...
}
}
The static
Log.Information(...) approach works perfectly well in .NET Framework
apps — the global logger picks it up and forwards it to all configured sinks, including LogInformant.
Configure Serilog via app.config / web.config
If you prefer config-file-based setup (handy if you want ops teams to change log levels without redeploying),
install Serilog.Settings.AppSettings:
powershell
Install-Package Serilog.Settings.AppSettings
xml — web.config (appSettings section)
<add key="serilog:minimum-level" value="Information" /> <add key="serilog:using:LogInformant" value="LogInformant.Serilog.DotNetFramework" /> <add key="serilog:write-to:LogInformant.apiUrl" value="https://app.loginformant.com" /> <add key="serilog:write-to:LogInformant.apiKey" value="YOUR-API-KEY-HERE" />
csharp — Global.asax.cs (reads all settings from config)
Log.Logger = new LoggerConfiguration()
.ReadFrom.AppSettings()
.CreateLogger();
Option B — NLog
1 Install NuGet packages
powershell — Package Manager Console
Install-Package NLog Install-Package LogInformant.NLog
2 Configure nlog.config
Add or update nlog.config at the root of your project:
xml — nlog.config
<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<extensions>
<add assembly="LogInformant.NLog"/>
</extensions>
<targets>
<target xsi:type="LogInformant"
name="loginformant"
apiUrl="https://app.loginformant.com"
apiKey="YOUR-API-KEY-HERE" />
</targets>
<rules>
<logger name="*" minlevel="Info" writeTo="loginformant" />
</rules>
</nlog>
3 Log in your code
csharp
using NLog;
public class OrderController : Controller
{
private static readonly ILogger Logger = LogManager.GetCurrentClassLogger();
public ActionResult PlaceOrder(int id)
{
Logger.Info("Order {0} placed", id);
try
{
// your logic
}
catch (Exception ex)
{
Logger.Error(ex, "Failed to place order {0}", id);
}
return View();
}
}
Option C — log4net
1 Install NuGet packages
powershell — Package Manager Console
Install-Package log4net Install-Package LogInformant.Log4Net
2 Configure log4net.config
xml — log4net.config
<?xml version="1.0" encoding="utf-8"?>
<log4net>
<appender name="LogInformant" type="LogInformant.Log4Net.LogInformantAppender">
<ApiUrl value="https://app.loginformant.com" />
<ApiKey value="YOUR-API-KEY-HERE" />
<BatchSize value="50" />
<FlushIntervalMs value="2000" />
</appender>
<root>
<level value="INFO" />
<appender-ref ref="LogInformant" />
</root>
</log4net>
3 Register in Global.asax.cs
csharp — Global.asax.cs
using log4net;
using log4net.Config;
protected void Application_Start()
{
// Tell log4net to read your config file
XmlConfigurator.Configure(new FileInfo(Server.MapPath("~/log4net.config")));
// ... rest of your startup
}
4 Log in your code
csharp
using log4net;
public class OrderController : Controller
{
private static readonly ILog Logger = LogManager.GetLogger(typeof(OrderController));
public ActionResult PlaceOrder(int id)
{
Logger.InfoFormat("Order {0} placed", id);
try
{
// your logic
}
catch (Exception ex)
{
Logger.Error("Failed to place order " + id, ex);
}
return View();
}
}
Log level mapping
| Serilog | NLog | log4net | LogInformant |
|---|---|---|---|
| Verbose | Trace | DEBUG | Debug |
| Debug | Debug | DEBUG | Debug |
| Information | Info | INFO | Information |
| Warning | Warn | WARN | Warning |
| Error | Error | ERROR | Error |
| Fatal | Fatal | FATAL | Fatal |