Wednesday, October 24, 2007

Log4net and .Net Compact Framework 1.0

Log4net, part of the Apache Logging Services project, can be a very helpful tool to log statements to different output targets. One of the features of log4net is the support for multiple frameworks. This post is just an extract from the Apache site that highlights the major differences of the compact version of log4net.

Microsoft .NET Compact Framework 1.0

* Assembly attributes
The .NET Compact Framework 1.0 does not support retrieving assembly level attributes, therefore all log4net configuration attributes were removed from the .NET Compact Framework 1.0 version of log4net.

For Smart-device applications, the log4net system can be configured by passing the location of the log4net configuration file to the log4net.Config.XmlConfigurator.Configure(FileInfo) method in the entry point of the application.

For example:

// Uncomment the next line to enable log4net internal debugging
// log4net.Util.LogLog.InternalDebugging = true;

// This will instruct log4net to look for a configuration file
// called config.log4net in the root directory of the device
log4net.Config.XmlConfigurator.Configure(new FileInfo(@"\config.log4net"));

// This will shutdown the log4net system
log4net.LogManager.Shutdown();


* Notification events
The .NET Compact Framework 1.0 does not support notification events during the application shutdown, therefore log4net cannot automatically hook the application shutdown notification.

Applications will need to programmatically shutdown the log4net system during the application's shutdown using the log4net.LogManager.Shutdown() method in order to prevent losing logging events. See the code above for an example.

* FileSystemWatcher
The .NET Compact Framework 1.0 does not support the System.IO.FileSystemWatcher class. As a result, the XmlConfiguratorAttribute.Watch property and the XmlConfigurator.ConfigureAndWatch methods are not available. Watching changes to the log4net configuration file is not supported on the .NET Compact Framework 1.0.

* UserName
The .NET Compact Framework 1.0 does not support the System.Security.Principal.WindowsIdentity class. This is used to capture the current thread's user identity. Therefore the LoggingEvent.UserName property will return the value "NOT AVAILABLE".

* Identity
The .NET Compact Framework 1.0 does not support the System.Security.Principal.IPrincipal interface. This is used to capture the current thread's user identity. Therefore the LoggingEvent.Identity property will return the value "NOT AVAILABLE".

* Environment variables
The .NET Compact Framework 1.0 does not support retrieving environment variables, therefore it's not possible to substitute environment variables in parameter values when using the .NET Compact Framework 1.0 version of log4net.

* Serialization
The .NET Compact Framework 1.0 does not support serialization, therefore none of the log4net classes in the .NET Compact Framework 1.0 version are serializable.

* LoggingEvent.Domain
The .NET Compact Framework 1.0 does not support AppDomain functionality. The friendly name for the current AppDomain is stored in the LoggingEvent.Domain property and is accessed using the %a pattern of the PatternLayout. On the .NET Compact Framework 1.0 this value is generated by taking the file name for the application's primary module.

Click here to visit the page directly.