Manages storage of logging information for ASP.NET web applications in a SQL Server database.

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

Syntax

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

Type.createClass(
	'CuttingEdge.Logging.Web.AspNetSqlLoggingProvider',
	CuttingEdge.Logging.SqlLoggingProvider);

Remarks

When the AspNetSqlLoggingProvider succeeds writing the event to the database, the Log method will return an Int32 with the unique id for the logging event generated by the database. Please note that the provider will return null when the event is not logged to the database. This happens in the following situations:

  • The provider's Threshold was set higher than the event's Severity.
  • There was an exception logging to the database and the event was logged successfully to the FallbackProvider.

The table below shows the list of valid attributes for the AspNetSqlLoggingProvider 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.
connectionStringName The connection string provided with this provider. This attribute is mandatory.
initializeSchema When this boolean attribute is set to true, the provider will try to create the needed tables and stored procedures in the database. This attribute is optional and false by default.
applicationName Specifies the name of the application to log with the request. This allows you to use a single logging store for multiple applications. This attribute is mandatory.
userNameRetrievalType The userNameRetrievalType attribute allows you to configure the source from which the provider tries to retrieve the user name of the current logged-on user (the user making the request). The options are None, Membership and WindowsIdentity; Use Membership to retrieve the user name from the current HttpContext. Use WindowsIdentity when you use windows authentication; Use None when you don't want any user information to be logged. This attribute is mandatory.
logQueryString When this boolean attribute is set to true, the provider will write the query string of the current HttpContext to the database. This attribute is optional and true by default.
logFormData When this boolean attribute is set to true, the provider will write the form data of the current HttpContext to the database. This attribute is optional and false by default.
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.
 Copy Code
  <?xml version="1.0"?>
  <configuration>
      <configSections>
          <section name="logging" type="CuttingEdge.Logging.LoggingSection, CuttingEdge.Logging"
              allowDefinition="MachineToApplication" />
      </configSections>
      <connectionStrings>
          <add name="SqlLogging"  
              connectionString="Data Source=.;Integrated Security=SSPI;Initial Catalog=Logging;" />
      </connectionStrings>
      <logging defaultProvider="AspNetSqlLoggingProvider">
          <providers>
              <add  
                  name="AspNetSqlLoggingProvider"
                  type="CuttingEdge.Logging.Web.AspNetSqlLoggingProvider, CuttingEdge.Logging"
                  description="ASP.NET SQL logging provider example"
                  connectionStringName="SqlLogging"
                  threshold="Information"
                  initializeSchema="True"
                  applicationName="MyWebApplication"
                  userNameRetrievalType="Membership"
                  logQueryString="True"
                  logFormData="False"
              />
          </providers>
      </logging>
      <system.web>
          <httpModules>
              <add name="ExceptionLogger"  
                  type="CuttingEdge.Logging.Web.AspNetExceptionLoggingModule, CuttingEdge.Logging"/>
          </httpModules>
      </system.web>
  </configuration>
  

Inheritance Hierarchy

See Also