Manages storage of logging information in a SQL Server database.
Namespace:
CuttingEdge.LoggingAssembly: CuttingEdge.Logging (in CuttingEdge.Logging.dll)
Syntax
| Visual Basic (Declaration) |
|---|
Public Class SqlLoggingProvider _ Inherits LoggingProviderBase |
| C# |
|---|
public class SqlLoggingProvider : LoggingProviderBase |
| Visual C++ |
|---|
public ref class SqlLoggingProvider : public LoggingProviderBase |
| JavaScript |
|---|
CuttingEdge.Logging.SqlLoggingProvider = function(); Type.createClass( 'CuttingEdge.Logging.SqlLoggingProvider', CuttingEdge.Logging.LoggingProviderBase); |
Remarks
When the SqlLoggingProvider 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.
This class is used by the Logger class to provide Logging services for an application using a SQL Server database. You cannot use a SqlLoggingProvider without SQL Server.
The table below shows the list of valid attributes for the SqlLoggingProvider configuration:
| Attribute | Description |
|---|---|
| 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. |
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="SqlLoggingProvider"> <providers> <add name="SqlLoggingProvider" type="CuttingEdge.Logging.SqlLoggingProvider, CuttingEdge.Logging" threshold="Information" connectionStringName="SqlLogging" initializeSchema="True" description="SQL logging provider" /> </providers> </logging> </configuration> | |
Inheritance Hierarchy
System..::.Object
System.Configuration.Provider..::.ProviderBase
CuttingEdge.Logging..::.LoggingProviderBase
CuttingEdge.Logging..::.SqlLoggingProvider
CuttingEdge.Logging.Web..::.AspNetSqlLoggingProvider
System.Configuration.Provider..::.ProviderBase
CuttingEdge.Logging..::.LoggingProviderBase
CuttingEdge.Logging..::.SqlLoggingProvider
CuttingEdge.Logging.Web..::.AspNetSqlLoggingProvider