Forwards logging information to other configured logging providers.

Namespace:  CuttingEdge.Logging
Assembly:  CuttingEdge.Logging (in CuttingEdge.Logging.dll)

Syntax

Visual Basic (Declaration)
Public Class CompositeLoggingProvider _
	Inherits LoggingProviderBase
C#
public class CompositeLoggingProvider : LoggingProviderBase
Visual C++
public ref class CompositeLoggingProvider : public LoggingProviderBase
JavaScript
CuttingEdge.Logging.CompositeLoggingProvider = function();

Type.createClass(
	'CuttingEdge.Logging.CompositeLoggingProvider',
	CuttingEdge.Logging.LoggingProviderBase);

Remarks

The CompositeLoggingProvider allows duplication and distribution of log events over multiple other logging providers. In conjunction with the usage of the Threshold attribute, this enables scenario's where users can log all events to a particular destination (such as SQL server) and at the same time log those events of a particular severity to another destination (such as sending by mail).

When a single provider is configured to which the CompositeLoggingProvider should forward logging events and it succeeds forwarding an event to that configured provider, the CompositeLoggingProvider will return the identifier returned that configured provider, or null when that provider returned null. When multiple providers are configured to which the CompositeLoggingProvider should forward logging events, it will always return null.

When the CompositeLoggingProvider's Threshold was set lower or equals to the event's Severity, it will log that event to all configured providers. The order in which the providers are called to log is determined by the configuration. Providers are ordered based on their number in the configuration. The attributes contain a number. See the list with the attribute specification for more information about this.

Even when one of the providers fails (by throwing an exception) during the forwarding process, the CompositeLoggingProvider will continue forwarding the event to the other providers. Because multiple providers could fail, multiple exceptions could be thrown. In the situation where multiple providers are configured, and one or more of those providers fail, the CompositeLoggingProvider will always wrap those exceptions (even if it is a single exception) in a CompositeException. This CompositeException will be forwarded to the configured FallbackProvider or, when no fallback provider is configured, thrown from the provider. When just a single provider is configured, the CompositeLoggingProvider will not wrap the thrown exception, but simply forward that to the FallbackProvider or, when no fallback provider is configured, let that exception bubble up the call stack.

The table below shows the list of valid attributes for the CompositeLoggingProvider configuration:

AttributeDescription
name The name of the provider. This attribute is mandatory.
description A description of the provider. This attribute is optional.
fallbackProvider A fallback provider that this provider will use when logging failed. The value must contain the name of an existing logging provider. This attribute is optional.
threshold The logging threshold. The threshold limits the number of events logged. The threshold can be defined as follows: Debug < Information < Warning < Error < Critical. i.e., When the threshold is set to Information, events with a severity of Debug will not be logged. When no value is specified, all events are logged. This attribute is optional.
provider[n] A provider that will be used to forward logging information to, where [n] is a arbitrary number. The value must contain the name of an existing logging provider. Multiple attributes can be specified, as long as [n] is unique. At Least one attribute must be specified.
The attributes can be specified within the provider configuration. See the example below on how to use.

Examples

This example demonstrates how to specify values declaratively for several attributes of the logging section, which can also be accessed as members of the LoggingSection class. The following configuration file example shows how to specify values declaratively for the logging section.

In this example a CompositeLoggingProvider is configured as default provider and it forwards all events to the configured SqlLoggingProvider and MailLoggingProvider. The SqlLoggingProvider will store all events in the database. The MailLoggingProvider is configured to mail only events with a severity of Error and Critical to a specified mail address.

 Copy Code
  <?xml version="1.0"?>
  <configuration>
      <configSections>
          <section name="logging" allowDefinition="MachineToApplication"
              type="CuttingEdge.Logging.LoggingSection, CuttingEdge.Logging" />
      </configSections>
      <connectionStrings>
          <add name="SqlLoggingConnection"  
              connectionString="Data Source=.;Integrated Security=SSPI;Initial Catalog=Logging;" />
      </connectionStrings>
      <logging defaultProvider="CompositeLoggingProvider">
          <providers>
              <add  
                  name="CompositeLoggingProvider"
                  type="CuttingEdge.Logging.CompositeLoggingProvider, CuttingEdge.Logging"
                  threshold="Debug"
                  provider1="SqlLoggingProvider"
                  provider2="MailLoggingProvider"
                  description="Composite logging provider"
              />
              <add  
                  name="SqlLoggingProvider"
                  type="CuttingEdge.Logging.SqlLoggingProvider, CuttingEdge.Logging"
                  connectionStringName="SqlLoggingConnection"
              />
              <add  
                  name="MailLoggingProvider"
                  type="CuttingEdge.Logging.MailLoggingProvider, CuttingEdge.Logging"
                  threshold="Error"
                  to="support@company.com"
              />
          </providers>
      </logging>
      <system.net>
          <mailSettings>
              <smtp from="test@foo.com">
                  <network
                      host="smtpserver1"  
                      port="25"  
                      userName="john"  
                      password="secret"  
                      defaultCredentials="true"
                  />
              </smtp>
          </mailSettings>
      </system.net>    
  </configuration>
  

Inheritance Hierarchy

System..::.Object
  System.Configuration.Provider..::.ProviderBase
    CuttingEdge.Logging..::.LoggingProviderBase
      CuttingEdge.Logging..::.CompositeLoggingProvider

See Also