Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Log4net: SysLog Appender Example

Tags:

log4net

syslog

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

like image 900
JL. Avatar asked Jan 06 '10 08:01

JL.


People also ask

What are log4net Appenders?

For log4net to know where to store your log messages, you add one or more appenders to your configuration. An appender is a C# class that can transform a log message, including its properties, and persist it somewhere. Examples of appenders are the console, a file, a database, an API call, elmah.io, etc.

Where are log4net logs stored?

You can configure the log4net. config file to create log files. The file is located in the webroot\App_data directory of the installation. The different log files are described in Services logs.


2 Answers

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 |  | 
like image 72
Orwellophile Avatar answered Oct 23 '22 13:10

Orwellophile


<appender name="UdpAppender" type="log4net.Appender.UdpAppender">
      <param name="RemoteAddress" value="127.0.0.1" />
      <param name="RemotePort" value="514" />
      <layout type="log4net.Layout.PatternLayout, log4net">
        <conversionPattern value="%-5level %logger [%property{NDC}] - %message%newline" />
      </layout>
</appender>
like image 43
JL. Avatar answered Oct 23 '22 14:10

JL.