Log4net: SysLog Appender Example

JL. picture JL. · Jan 6, 2010 · Viewed 28.3k times · Source

I am looking for example configuration on how to get Log4net logging to a Syslog server. Any help would be welcome.

Answer

Orwellophile picture Orwellophile · Jun 21, 2012

I didn't find Simon Whittemore's entry very helpful, this is what got my appender producing "proper" syslog remote messages:

<appender name="RemoteSyslogAppender" type="log4net.Appender.RemoteSyslogAppender">
  <identity value="HepeManok" />
  <layout type="log4net.Layout.PatternLayout" value="%-5p %type: %m%n"/>
  <remoteAddress value="syslog.lameserver.net" />
</appender>

The "key" [sic] is the identity parameter, that produces the correct (or correct looking) output - I'm using rsyslog on Debian, YMMV.

You most definitely do not need or want to send the date (as in Simon Whittemore's blog), as syslogd will add the date for you, using the server's timezone.

Here's a received message from my log4net enabled app, followed by a real message:

Jun 21 09:58:40 vs2008.local HepeManok: INFO  Irc: irc_OnConnected
Jun 21 09:42:45 chips30 kernel: [10210014.974069] device eth0 entered promiscuous mode

As you can see, the basic format of "Date Time Host Service: message" is all good, unlike

Jun 21 09:38:57 WARN  Irc [(null)] - OnQuit#015

or an example of what Simon's config would produce:

Jun 21 09:56:42 Hepe Manok.vshost.exe: 21/06/2012 07:54:44,828 | 6 | INFO | Irc | WIN-2008-DEV\Administrator | WIN-2008-DEV | dev | irc_OnConnecting |  |