New CLI build
A new log4net assembly is built that targets all CLI 1.0 compatible runtimes. This build is essentially a common subset of the Mono 1.0 and .NET 1.0 builds. It is built using the MS .NET 1.0 compiler and libraries but does not use any platform specific APIs.
This build is only available in release configuration and can be found at bin\cli\1.0\release.
Logging contexts
Logging contexts can be used to record contextual data that is relevant to the current process. Logging contexts are both an extension of the concepts embodied in the MDC and NDC and a replacement for them. The MDC and NDC have been reimplemented to use the ThreadContext as storage.
The logging contexts provide a single unified view that cuts across different scopes within an application. The contexts are layered in the following order of narrowing scope: GlobalContext, ThreadContext, LogicalThreadContext, and LoggingEvent. Context values specified in a narrower scope hide the matching value in a wider scope.
PatternLayout customization and long pattern names
The PatternLayout now supports long pattern names. These pattern names are significantly more readable than the single character patterns.
The PatternLayout now supports custom patterns. New patterns can be defined in the config file:
<layout type="log4net.Layout.PatternLayout"> <converter> <name value="myConverter" /> <type value="TestApp.MyPatternConverter, TestApp" /> </converter> <conversionPattern value="%-5level %logger - %myConverter - %message%newline" /></layout>
The above config defines a custom pattern called myConverter which is bound to the TestApp.MyPatternConverter, TestApp type. This type must extend the log4net.Util.PatternConverter base class. The custom pattern can then be used in the pattern string.
For full details see the SDK Reference entry: log4net.Layout.PatternLayout.
PatternString for pattern based configuration
A new pattern based type, PatternString, can be used in the config file to set string properties using a pattern syntax. For example the File property of the FileAppender could be set as follows:
<file type="log4net.Util.PatternString"> <converter> <name value="folder" /> <type value="TestApp.SpecialFolderPatternConverter,TestApp" /> </converter> <conversionPattern value="%folder{LocalApplicationData}\log-file.txt" /></file>The code for the SpecialFolderPatternConverter is as follows:
public class SpecialFolderPatternConverter : log4net.Util.PatternConverter { override protected void Convert(System.IO.TextWriter writer, object state) { Environment.SpecialFolder specialFolder = (Environment.SpecialFolder)Enum.Parse(typeof(Environment.SpecialFolder), base.Option, true); writer.Write(Environment.GetFolderPath(specialFolder)); }}For full details see the SDK Reference entry: log4net.Util.PatternString.
Loading configuration from a URI
The XmlConfigurator methods now support loading the configuration data from a URI. Config can be loaded from any URI supported by the System.Net.WebRequest class.
Support for No-Touch deployment
Log4net supports configuring No-Touch deployment applications using the XmlConfiguratorAttribute. If a relative config file or extension is specified then this is resolved relative to the deployment URI.
Config file parser enhancements
The config file parser has been enhanced to support specifying the property subtype, or intermediate type, directly on the property element, for example:
<layout type="log4net.Layout.PatternLayout" value="%message%newline" />
Implicit conversion will be attempted between the value string and the type specified, and then again between the type and the target property type.
.NET string formatting syntax
Added .NET String.Format style formatting syntax methods to the ILog interface. The new methods are: DebugFormat, InfoFormat, WarnFormat, ErrorFormat and FatalFormat.
Customizable levels
Levels are defined by the repository LevelMap. The defined levels, the relative ordering of levels and level display names can be configured on a per-repository basis.
Per-appender security contexts
Appenders that interact with controlled platform resources, e.g. files, can be configured to use a separate security context when accessing these resources. The calling thread may not have appropriate privileges to access the resource a custom SecurityContext can be used to elevate the privileges of the appender. The WindowsSecurityContext is used to specify alternative credentials on the Windows platform.
Added new appenders
- AnsiColorTerminalAppender
The AnsiColorTerminalAppender writes events to the application's ANSI terminal window. It can be configured to specify the text and background colors for different level events. Note that Console applications running on Windows do not have an ANSI terminal window and should use the ColoredConsoleAppender instead.
- LocalSyslogAppender
Logs events to a local syslog service. This appender uses the POSIX libc syslog library functions. If these functions are not available on the local system then this appender will not work!
- RemoteSyslogAppender
The RemoteSyslogAppender uses the BSD syslog protocol to log to a syslog daemon. The syslogd listens for for messages on UDP port 514.
- TelnetAppender
The TelnetAppender accepts socket connections and streams logging messages back to the client. The output is provided in a telnet-friendly way so that a log can be monitored over a TCP/IP socket. This allows simple remote monitoring of application logging.
Added new LoggerMatchFilter filter
Added LoggerMatchFilter which matches a string against the event's logger name.
Pluggable file locking models for the FileAppender
The FileAppender (and by extension the RollingFileAppender) now support pluggable file locking models. The default model, ExclusiveLock, maintains the current exclusive file locking behavior. An alternative model, MinimalLock, can be used to support writing to a single output file from multiple processes.
For full details see the SDK Reference entry: log4net.Appender.FileAppender.LockingModel.
RollingFileAppender roll once
The RollingFileAppender now supports a new rolling style, Once. In this mode the appender will roll the file once per run.
SmtpAppender authentication
On the .NET 1.1 platform only, the SmtpAppender supports authenticating against the mail server using either username and password or integrated NTLM authentication.
AdoNetAppender ReconnectOnError
Added new configuration property to AdoNetAppender. Setting ReconnectOnError to true will force the appender to attempt to reconnect to the database if the connection is lost.
UdpAppender hostname support
The UdpAppender config property RemoteAddress can now be specified as a DNS hostname string. The hostname is resolved to an IP address.