Appenders
Appenders are responsible for delivering log events to their destination.
Every Appender must implement the IAppender
interface.
While not strictly required by the log4net architecture, most appenders inherit from AppenderSkeleton
and:
Appenders always have a name so that they can be referenced from a logger configuration.
List of appenders
log4net ships with the following appenders
Type | Description |
---|---|
Writes logging events to a database using either prepared statements or stored procedures. |
|
AnsiColorTerminalAppender |
Writes color highlighted logging events to a an ANSI terminal window. |
AspNetTraceAppender |
Writes logging events to the ASP trace context. These can then be rendered at the end of the ASP page or on the ASP trace page. |
Buffers events and then forwards them to attached appenders. |
|
Writes color highlighted logging events to the application’s Windows Console. |
|
Writes logging events to the application’s Console. The events may go to either the standard our stream or the standard error stream. |
|
DebugAppender |
Writes logging events to the .net debugger (System.Diagnostics.Debug). |
Writes logging events to the Windows Event Log. |
|
Writes logging events to a file in the file system. |
|
Writes logging events to the local syslog service (UNIX only). |
|
Writes color highlighted logging events to the application’s Windows Console. This appender is a managed version of the ColoredConsoleAppender and does not require the use of the Windows Console API. It is a replacement for the ColoredConsoleAppender and is the recommended appender for logging to the Console. |
|
Stores logging events in an in memory buffer. |
|
Writes logging events to the debugger (using OutputDebugString). If the application has no debugger, the system debugger displays the string. If the application has no debugger and the system debugger is not active, the message is ignored. |
|
Writes logging events to a remote syslog service using UDP networking. |
|
Writes logging events to a file in the file system. The RollingFileAppender can be configured to log to multiple files based upon date or file size constraints. |
|
Sends logging events to an email address. |
|
Sends logging events to an email address but writes the emails to a configurable directory rather than sending them directly via SMTP. |
|
TelnetAppender |
Clients connect via Telnet to receive logging events. |
Writes logging events to the .NET trace system (System.Diagnostics.Trace). |
|
Sends logging events as connectionless UDP datagrams to a remote host or a multicast group using a UdpClient. |
|
Can be used to wrap another appender, for example to attach additional filters. |
Appender Additivity
A logger can have multiple appenders.
Each enabled logging request is passed to all appenders attached to that logger, and also to appenders higher in the logger hierarchy. This behavior is called appender additivity and is enabled by default.
For example, if a console appender is attached to the root logger, all enabled logs will at least print to the console.
If a file appender is added to logger X
, logs from X
and its children will go to both the file and the console.
Additivity can be disabled by setting a logger’s additivity
flag to false
.
This prevents logging events from being passed to ancestor appenders beyond that point.
If the |
Logger Name | Added Appenders | Additivity Flag | Output Targets | Comment |
---|---|---|---|---|
root |
ConsoleAppender |
not applicable |
ConsoleAppender |
Default appender at the root. |
Animals |
FileAppender, RollingFileAppender |
true |
ConsoleAppender, FileAppender, RollingFileAppender |
Appenders of "Animals" and root. |
Animals.Carnivora |
none |
true |
ConsoleAppender, FileAppender, RollingFileAppender |
Inherited from "Animals" and root. |
Animals.Carnivora.Felidae |
SmtpAppender |
true |
ConsoleAppender, FileAppender, RollingFileAppender, SmtpAppender |
Appenders in "Animals.Carnivora.Felidae", "Animals", and root. |
Security |
UdpAppender |
false |
UdpAppender |
No appender accumulation because additivity is set to false. |
Security.Access |
none |
true |
UdpAppender |
Only appenders of "Security" are used due to disabled additivity in "Security". |