This project has moved and is read-only. For the latest updates, please go here.

See also

CuttingEdge.Logging configuration examples

This page shows configuration examples for all parts of the CuttingEdge.Logging framework. Please consult the CuttingEdge.Logging Reference Library  for more information.

Contents

 

Basic configuration

The following example shows a the app.config of a typical application that uses CuttingEdge.Logging. This configuration in this example allows logging to the Windows event log.

<?xml version="1.0"?>
<configuration>
<configSections>
<!-- The following section should be added to the configSections. -->
<section name="logging"
type="CuttingEdge.Logging.LoggingSection, CuttingEdge.Logging" />
</configSections>
<!-- the logging section allows you to configure logging providers -->
<logging defaultProvider="WindowsEventLogger">
<providers>
<!-- The WindowsEventLogLoggingProvider writes to the event log -->
<add name="WindowsEventLogger"
type="CuttingEdge.Logging.WindowsEventLogLoggingProvider, CuttingEdge.Logging"
source="[MyApplication]"
logName="[MyApplication]" />
</providers>
</logging>
</configuration>

Alternatively named configuration section

CuttingEdge.Logging allows you are allowed to name the configuration section differently. This allows you to use CuttingEdge.Logging together with another logging framework in the same application. Mixing frameworks would have been a problem when both frameworks expect the same section name.

The following example shows a the app.config of a typical application that uses CuttingEdge.Logging with an alternatively named logging section.

<?xml version="1.0"?>
<configuration>
<configSections>
<section name="cuttingEdgeLogging"
type="CuttingEdge.Logging.LoggingSection, CuttingEdge.Logging" />
</configSections>
<cuttingEdgeLogging defaultProvider="WindowsEventLogger">
<providers>
<add name="WindowsEventLogger"
type="CuttingEdge.Logging.WindowsEventLogLoggingProvider, CuttingEdge.Logging"
source="[MyApplication]"
logName="[MyApplication]" />
</providers>
</cuttingEdgeLogging>
</configuration>

Complete configuration example for ASP.NET

The following example shows a web.config of a typical ASP.NET application that uses CuttingEdge.Logging. This configuration uses the following components: The AspNetSqlLoggingProvider for logging to an Microsoft SQL Server database; the WindowsEventLogLoggingProvider to log events to when the AspNetSqlLoggingProvider fails; the AspNetExceptionLoggingModule that implements a catch-all mechanism for logging exceptions and; the LoggingWebEventProvider that routes web events fired by the ASP.NET health monitoring system to the logging infrastructure. The AspNetSqlLoggingProvider is configured in such a way that it will create the needed database schema in the configured database.

<?xml version="1.0"?>
<configuration>
<configSections>
<section name="logging" type="CuttingEdge.Logging.LoggingSection, CuttingEdge.Logging" />
</configSections>
<connectionStrings>
<add name="SqlLoggingConnection"
connectionString="Data Source=.;Integrated Security=SSPI;Initial Catalog=Logging;" />
</connectionStrings>
<logging defaultProvider="AspNetSqlLogger">
<providers>
<add name="AspNetSqlLogger"
type="CuttingEdge.Logging.Web.AspNetSqlLoggingProvider, CuttingEdge.Logging"
fallbackProvider="WindowsEventLogger"
connectionStringName="SqlLoggingConnection"
threshold="Information"
initializeSchema="True"
applicationName="[MyWebApplication]"
userNameRetrievalType="Membership"
logQueryString="True"
logFormData="False"
/>
<add name="WindowsEventLogger"
type="CuttingEdge.Logging.WindowsEventLogLoggingProvider, CuttingEdge.Logging"
threshold="Warning"
source="[MyWebApplication]"
logName="[MyWebApplication]" />
</providers>
</logging>
<system.web>
<httpModules>
<!-- We're defining the AspNetExceptionLoggingModule here. -->
<add name="ExceptionLogger"
type="CuttingEdge.Logging.Web.AspNetExceptionLoggingModule, CuttingEdge.Logging"/>
</httpModules>
<healthMonitoring heartbeatInterval="0" enabled="true">
<providers>
<!-- We're configuring the web event provider here. -->
<add name="LoggingWebEventProvider"
type="CuttingEdge.Logging.Web.LoggingWebEventProvider, CuttingEdge.Logging"
loggingProvider="AspNetSqlLogger" />
</providers>
<rules>
<add name="Custom Event Provider"
eventName="All Events"
provider="LoggingWebEventProvider"
profile="Default" />
</rules>
</healthMonitoring>
</system.web>
<system.webServer>
<modules>
<!-- We're defining the AspNetExceptionLoggingModule here. -->
<add name="ExceptionLogger"
type="CuttingEdge.Logging.Web.AspNetExceptionLoggingModule, CuttingEdge.Logging"/>
</modules>
</system.webServer>
</
configuration>

Configuring the ConsoleLoggingProvider

The ConsoleLoggingProvider manages the writing of logging information to the Console.

<?xml version="1.0"?>
<configuration>
<configSections>
<section name="logging" type="CuttingEdge.Logging.LoggingSection, CuttingEdge.Logging" />
</configSections>
<logging defaultProvider="ConsoleLogger">
<providers>
<add name="ConsoleLogger"
type="CuttingEdge.Logging.ConsoleLoggingProvider, CuttingEdge.Logging"
description="Console logging provider"
threshold="Warning" />
</providers>
</logging>
</configuration>
For more information, please see the ConsoleLoggingProvider in the reference library.

Configuring the CompositeLoggingProvider

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).

<?xml version="1.0"?>
<configuration>
<configSections>
<section name="logging"
type="CuttingEdge.Logging.LoggingSection, CuttingEdge.Logging" />
</configSections>
<connectionStrings>
<add name="SqlLoggingConnection"
connectionString="Data Source=.;Integrated Security=SSPI;Initial Catalog=Logging;" />
</connectionStrings>
<logging defaultProvider="CompositeLogger">
<providers>
<add
name="CompositeLogger"
type="CuttingEdge.Logging.CompositeLoggingProvider, CuttingEdge.Logging"
threshold="Information"
provider1="SqlLogger"
provider2="MailLogger"
description="Composite logging provider"
/>
<add
name="SqlLogger"
type="CuttingEdge.Logging.SqlLoggingProvider, CuttingEdge.Logging"
connectionStringName="SqlLoggingConnection"
/>
<add
name="MailLogger"
type="CuttingEdge.Logging.MailLoggingProvider, CuttingEdge.Logging"
threshold="Error"
to="support@company.com"
/>
</providers>
</logging>
<system.net>
<mailSettings>
<smtp from="errors@company.com">
<network
host="smtpserver1"
port="25"
userName="john"
password="secret"
defaultCredentials="true"
/>
</smtp>
</mailSettings>
</system.net>
</configuration>
For more information, please see the CompositeLoggingProvider in the reference library.

Configuring the DebugLoggingProvider

The DebugLoggingProvider manages the writing of logging information to the Debug output.

<?xml version="1.0"?>
<configuration>
<configSections>
<section name="logging" type="CuttingEdge.Logging.LoggingSection, CuttingEdge.Logging" />
</configSections>
<logging defaultProvider="DebugLogger">
<providers>
<add name="DebugLogger"
type="CuttingEdge.Logging.DebugLoggingProvider, CuttingEdge.Logging"
description="Debug logging provider"
threshold="Warning" />
</providers>
</logging>
</configuration>
For more information, please see the DebugLoggingProvider in the reference library.

Configuring the MemoryLoggingProvider

The MemoryLoggingProvider manages storage of logging information into memory. Use the GetLoggedEntries method to retrieve a copy of the internal cache and Clear to clear the internal cache. Because it contains an ever increasing internal cache, the MemoryLoggingProvider is not intended to be used in production environments.

<?xml version="1.0"?>
<configuration>
<configSections>
<section name="logging" type="CuttingEdge.Logging.LoggingSection, CuttingEdge.Logging" />
</configSections>
<logging defaultProvider="MemoryLogger">
<providers>
<add name="MemoryLogger"
type="CuttingEdge.Logging.MemoryLoggingProvider, CuttingEdge.Logging"
description="Memory logging provider"
threshold="Debug" />
</providers>
</logging>
</configuration>
For more information, please see the MemoryLoggingProvider in the reference library.

Configuring the MailLoggingProvider

The MailLoggingProvider manages sending of logging information by mail. This class is used by the Logger class to provide Logging services for an application that can connect to a configured SMTP Server. The MailLoggingProvider uses the configuration of the <system.net><mailSettings> section on the application configuration file.

<?xml version="1.0"?> 
<configuration>
<configSections>
<section name="logging" type="CuttingEdge.Logging.LoggingSection, CuttingEdge.Logging" />
</configSections>
<logging defaultProvider="MailLogger">
<providers>
<add name="MailLogger"
type="CuttingEdge.Logging.MailLoggingProvider, CuttingEdge.Logging"
description="Mail logging provider"
threshold="Information"
subjectFormatString="{0} reported on server01: {1}"
to="dev1@company.com;dev2@company.com"
/>
</providers>
</logging>
<system.net>
<mailSettings>
<smtp from="errors@company.com">
<network
host="smtpserver1"
port="25"
userName="john"
password="secret"
defaultCredentials="true"
/>
</smtp>
</mailSettings>
</system.net>
</configuration>
The subjectFormatString attribute is optional and allows you to change the subject of the mail message. It will be formatted as "{severity}: {event message}" by default. For more information about how to change the subjectFormatString and the MailLoggingProvider in general, please see the MailLoggingProvider in the reference documentation.

Configuring the SqlLoggingProvider

The SqlLoggingProvider manages storage of logging information in a SQL Server database.

<?xml version="1.0"?>
<configuration>
<configSections>
<section name="logging" type="CuttingEdge.Logging.LoggingSection, CuttingEdge.Logging" />
</configSections>
<connectionStrings>
<add name="SqlLogging"
connectionString="Data Source=.;Integrated Security=SSPI;Initial Catalog=Logging;" />
</connectionStrings>
<logging defaultProvider="SqlLogger">
<providers>
<add name="SqlLogger"
type="CuttingEdge.Logging.SqlLoggingProvider, CuttingEdge.Logging"
threshold="Information"
connectionStringName="SqlLogging"
initializeSchema="true"
description="SQL logging provider" />
</providers>
</logging>
</configuration>
This provider depends on two stored procedures. The SQL scripts to generate these stored procedures and the underlying data model can be found in the Sql Scripts folder of the library’s download. Alternatively, you can configure the provider with the option initializeSchema=”true”, as shown in the example above. Setting this option to true informs the provider to automatically create the schema. For more information, please see the SqlLoggingProvider in the reference library.

Configuring the TerminatorLoggingProvider

The default behavior of CuttingEdge.Logging is to let exceptions, caused by a failing provider, bubble up the call stack. The philosophy of CuttingEdge.Logging is that a failing provider is a serious problem and should not be ignored. For this reason CuttingEdge.Logging contains the notion of FallbackProviders. When a provider fails, the original event (and the exception thrown by the provider) will be routed to the fallback provider. In certain scenario's however, developers may want the application to be more robust and continue execution, even when logging fails. This can be the case when no suited fallback provider is available or the fallback provider could also fail. While these scenario's should be rare, the TerminatorLoggingProvider enables this. By using a TerminatorLoggingProvider, events going through that provider will get trashed and the application continues execution.

<?xml version="1.0"?>
<configuration>
<configSections>
<section name="logging"
type="CuttingEdge.Logging.LoggingSection, CuttingEdge.Logging" />
</configSections>
<connectionStrings>
<add name="SqlLoggingConnection"
connectionString="Data Source=.;Initial Catalog=Logging;Integrated Security=SSPI;" />
</connectionStrings>
<logging defaultProvider="SqlLogger">
<providers>
<add
name="SqlLogger"
type="CuttingEdge.Logging.SqlLoggingProvider, CuttingEdge.Logging"
fallbackProvider="Terminator"
connectionStringName="SqlLoggingConnection"
/>
<add
name="Terminator"
type="CuttingEdge.Logging.TerminatorLoggingProvider, CuttingEdge.Logging"
/>
</providers>
</logging>
</configuration>
For more information, please see the TerminatorLoggingProvider in the reference library.

Configuring the WindowsEventLogLoggingProvider

The WindowsEventLogLoggingProvider manages storage of Logging information to the Windows event log.

<?xml version="1.0"?>
<configuration>
<configSections>
<section name="logging" type="CuttingEdge.Logging.LoggingSection, CuttingEdge.Logging" />
</configSections>
<logging defaultProvider="WindowsEventLogger">
<providers>
<add name="WindowsEventLogger"
type="CuttingEdge.Logging.WindowsEventLogLoggingProvider, CuttingEdge.Logging"
threshold="Warning"
source="MyApplication"
logName="MyApplication"
description="Windows event log logging provider" />
</providers>
</logging>
</configuration>
For more information, please see the WindowsEventLogLoggingProvider in the reference library.

Configuring the XmlFileLoggingProvider

The XmlFileLoggingProvider manages storage of Logging information in XML format to the file system.

<?xml version="1.0"?>
<configuration>
<configSections>
<section name="logging" type="CuttingEdge.Logging.LoggingSection, CuttingEdge.Logging" />
</configSections>
<logging defaultProvider="XmlLogger">
<providers>
<add name="XmlLogger"
type="CuttingEdge.Logging.XmlFileLoggingProvider, CuttingEdge.Logging"
threshold="Information"
path="log.xml"
description="XML file logging provider" />
</providers>
</logging>
</configuration>
For more information, please see the XmlFileLoggingProvider in the reference library.

Configuring the AspNetExceptionLoggingModule

The AspNetExceptionLoggingModule is an HttpModule that enables logging of unhandled exceptions in web applications. When the AspNetExceptionLoggingModule is configured, unhandled exceptions will be send to the default logging provider.

<?xml version="1.0"?>
<configuration>
<configSections>
<section name="logging" type="CuttingEdge.Logging.LoggingSection, CuttingEdge.Logging" />
</configSections>
<logging defaultProvider="WindowsEventLogger">
<providers>
<!-- Define your favorite logging provider here -->
<add name="WindowsEventLogger"
type="CuttingEdge.Logging.WindowsEventLogLoggingProvider, CuttingEdge.Logging"
threshold="Information"
source="MyWebApplication"
logName="MyWebApplication"
description="Windows event log logging provider" />
</providers>
</logging>
<system.web>
<httpModules>
<!-- We're defining the AspNetExceptionLoggingModule here. -->
<add name="ExceptionLogger"
type="CuttingEdge.Logging.Web.AspNetExceptionLoggingModule, CuttingEdge.Logging"/>
</httpModules>
</system.web>
<system.webServer>
<modules>
<!-- We're defining the AspNetExceptionLoggingModule for IIS7 here. -->
<add name="ExceptionLogger"
type="CuttingEdge.Logging.Web.AspNetExceptionLoggingModule, CuttingEdge.Logging"/>
</modules>
</system.webServer>
</configuration>
For more information, please see the AspNetExceptionLoggingModule in the reference library.

Configuring the AspNetSqlLoggingProvider

The AspNetSqlLoggingProvider manages storage of logging information for ASP.NET web applications in a SQL Server database. It enables storing query string and form data, user name, ip-address and application name with each logged event.

<?xml version="1.0"?>
<configuration>
<configSections>
<section name="logging" type="CuttingEdge.Logging.LoggingSection, CuttingEdge.Logging" />
</configSections>
<connectionStrings>
<add name="SqlLogging"
connectionString="Data Source=.;Integrated Security=SSPI;Initial Catalog=Logging;" />
</connectionStrings>
<logging defaultProvider="AspNetSqlLogger">
<providers>
<add name="AspNetSqlLogger"
type="CuttingEdge.Logging.Web.AspNetSqlLoggingProvider, CuttingEdge.Logging"
description="ASP.NET SQL logging provider"
connectionStringName="SqlLogging"
threshold="Information"
initializeSchema="true"
applicationName="MyWebApplication"
userNameRetrievalType="Membership"
logQueryString="False"
logFormData="False" />
</providers>
</logging>
</configuration>
This provider depends on two stored procedures. The SQL scripts to generate these stored procedures and the underlying data model can be found in the Sql Scripts folder of the library’s download. Alternatively, you can configure the provider with the option initializeSchema=”true”, as shown in the example above. Setting this option to true informs the provider to automatically create the schema. For more information, please see the AspNetSqlLoggingProvider in the reference library.

Configuring the AspNetTraceLoggingProvider

The AspNetTraceLoggingProvider manages the writing of logging information in ASP.NET applications to the ASP.NET TraceContext system. This information will be visible on each web page when pages are configured to show tracing.

<?xml version="1.0"?>
<configuration>
<configSections>
<section name="logging" type="CuttingEdge.Logging.LoggingSection, CuttingEdge.Logging" />
</configSections>
<logging defaultProvider="AspNetTraceLogger">
<providers>
<add name="AspNetTraceLogger"
type="CuttingEdge.Logging.Web.AspNetTraceLoggingProvider, CuttingEdge.Logging"
threshold="Warning"
description="ASP.NET trace logging provider" />
</providers>
</logging>
</configuration>
For more information, please see the AspNetTraceLoggingProvider in the reference library.

Configuring the LoggingWebEventProvider

The LoggingWebEventProvider provider implements an web event provider (not a logging provider!) that saves ASP.NET event notifications using the Logging infrastructure.

<?xml version="1.0"?>
<configuration>
<configSections>
<section name="logging" type="CuttingEdge.Logging.LoggingSection, CuttingEdge.Logging" />
</configSections>
<logging defaultProvider="DebugLogger">
<providers>
<!-- Configure your favorite provider here. -->
<add name="DebugLogger"
type="CuttingEdge.Logging.DebugLoggingProvider, CuttingEdge.Logging"
description="Debug logging provider"
threshold="Debug" />
</providers>
</logging>
<system.web>
<healthMonitoring heartbeatInterval="0" enabled="true">
<providers>
<!-- We're configuring the web event provider here. -->
<add name="LoggingWebEventProvider"
type="CuttingEdge.Logging.Web.LoggingWebEventProvider, CuttingEdge.Logging"
loggingProvider="DebugLogger" />
</providers>
<rules>
<add name="Custom Event Provider"
eventName="All Events"
provider="LoggingWebEventProvider"
profile="Default" />
</rules>
</healthMonitoring>
</system.web>
</configuration>
For more information, please see the LoggingWebEventProvider in the reference library.

More information

For more information about CuttingEdge.Logging, please visit the following links:

Last edited Apr 1, 2011 at 1:18 PM by dot_NET_Junkie, version 25