Filtering Telnet Appender


When doing bigger projects, especially with a distributed infrastructure, solid logging is crucial. In the .NET world, the log4net framework is quite popular for this task, it's free for commerical and non commercial use, comes with a log of built in functionality and is still very light weight and easy to implement. To provide means of log output, log4net offers more than just plain text files. Further options include sending mails, Syslog daemons, Windows event log or database logging. At work, we use the telnet appender to log low level framework debug information, simply because there is too much of it to pipe it out to files all of the time. With the telnet logger, you append to a Tcp port (by default 23, which is the telnet port) and can then get the current debug output with a simple telnet client like Putty.

As mentioned before, the logs are quite exhaustive and searching for anything in particular becomes quite a hassle like this. To remedy the situation, I did an appender which is quite similar to the telnet appender, however it can be configured to filter down the logging output by issuing commands via telnet.

Installing and Configuring the Appender

Configuration works pretty much the same way, as with the telnet appender, only the class and assembly are different. Here is a sample configuration:

<?xml version="1.0" encoding="utf-8" ?>
    <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />

  <log4net debug="false">
    <appender name="ConsoleAppender" type="Schommer.Projects.log4net.FilteringTelnetAppender, FilteringTelnetAppender" >
      <layout type="log4net.Layout.PatternLayout,log4net">
        <param name="ConversionPattern" value="%d [%t] %-5p %c [%x] &lt;%X{auth}&gt; - %m%n" />
      <priority value="ALL" />
      <appender-ref ref="ConsoleAppender" />
For further information on how to configure log4net in general or how to configure the telnet appender (e.g. the port) check out this page. 
Don't forget to reference the FilteringTelnetAppender.dll assembly in your project to make the appender work.

Interacting with the Appender via Telnet

When connecting with the appender via telnet, you'll recieve a short summary of known commands. When no further configuration is done, the appender will act just like the normal telnet appender routing all output through.

Use +[pattern] to add patterns to filter on. For example if you just want to see output that contains either the word ERROR or WARNING, enter the following:


Search of strings in the log messages is case insensitive.

If you want to remove a filter, for example the WARNING filter, enter the following:


Just hitting return will show the currently active filters, and .[RETURN] will clear all filters.

Note, that filters are specified on a per connection basis; this means, that each telnet client connecting can maintain his own filters in his session.

Final Words

I hope you'll find this appender quite useful. I included the source, as well as the binaries. Most of the code has been copied from the telnet appender, unfortunately I could not really inherit from it. Feel free to use or modify the appender the way you like, just give some hugs to me and the original authors of the telnet appender.

In case you have problem getting the binary to run I suggest, that you recompile the source against the version of log4net that you are using. (4,69 kb) (259,54 kb)

About the author

for comments and suggestions contact:


Month List