Home

Castle Stronghold

Logging Facility

The Logging Facility provides custom loggers for your components.

Facility Summary
Uses ProxyNo
Requires configurationYes
Uses attributeNo
Version1.0 RC 2
Maturity levelHigh

Introduction

The logging facility provides a seemless way to add logging capabilities to your application. There are two levels of integration.

Loggers

You can use the following loggers implementations:

Quick start

Your first step is to add the Logging Facility into your Windsor container, either by using the configuration schema listed below, or in code.


<?xml version="1.0" encoding="utf-8" ?> 
<configuration>

<facility 
    id="logging"
    type="Castle.Facilities.Logging.LoggingFacility, Castle.Facilities.Logging"
    loggingApi="null|console|diagnostics|web|nlog|log4net|custom"
    customLoggerFactory="type name that implements ILoggerFactory"
    configFile="optional config file location"    />

</configuration>

Best practices

We recommend that you make logging optional on your components/services. This way you maximize the reusability. For example:


using Castle.Core.Logging;
    
public class CustomerService
{
    private ILogger logger = NullLogger.Instance;

    public CustomerService()
    {
    }
    
    public ILogger Logger
    {
        get { return logger; }
        set { logger = value; }
    }

    ...
}

With the approach above, the logger field will never be null. Also, if the logging facility was registered on the container, it will be able to supply a logger instance using the Logger property.

Required Assemblies

Google
Search WWW Search castleproject.org