Documentation
DocumentationDiscussions
Documentation

log4net

A log4net appender is provided that writes events to Seq via HTTP.

🚧

Like much of the log4net ecosystem, Seq's support for log4net is in maintenance mode.

Seq works best with richly-structured event data like that produced by Serilog, ASP.NET Core and NLog. These libraries are actively developed and have up-to-date support for modern application requirements.

Installing the Appender

At the time of writing, the Seq appender for log4net supports .NET 4+.

At the Visual Studio Package Manager console, type:

PM> Install-Package Seq.Client.Log4Net PM> Install-Package Log4Net.Async

This will add the required assemblies to the project.

Then, add the Seq appender to your log4net configuration. This is wrapped in a Log4Net.Async AsyncForwardingAppender so that the application does not pause while log events are flushed to Seq:

<?xml version="1.0" encoding="utf-8" ?> <configuration> <configSections> <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" /> </configSections> <log4net> <appender name="SeqAppender" type="Seq.Client.Log4Net.SeqAppender, Seq.Client.Log4Net" > <bufferSize value="1" /> <serverUrl value="http://localhost:5341" /> <apiKey value="" /> </appender> <appender name="SeqAsyncForwarder" type="Log4Net.Async.AsyncForwardingAppender,Log4Net.Async"> <appender-ref ref="SeqAppender" /> </appender> <root> <level value="INFO" /> <appender-ref ref="SeqAsyncForwarder" /> </root> </log4net> </configuration>

Set the serverUrl value under to the address of your Seq server.

This example sets the Seq appender's bufferSize to 1 so that events appear immediately; in a production setting, use a higher value - at least 100. This will delay sending of events until the buffer fills, so to keep data flowing when volumes are low, consider periodically calling LogManager.Flush().

Writing events

That's it! When you write log events to your log4net ILogger:

log.InfoFormat("Hello, {0}, from log4net!", Environment.UserName);

They'll appear beautifully in Seq.


Did this page help you?