Microsoft SQL Server Writer

Class names

Writer: NSoft.Log.Writers.DB.DBLogWriter.
Configuration: NSoft.Log.Writers.DB.DBLogWriterSettings.

Description

This writer stores data to database.
  • For single records it generates query without type information. If data should be converted - SQL Server will do it.
  • For multiple records bulk insert is used.
Number of data items must be equal to table columns count. For example if table have two columns - data must have exactly two items.
Each channel will be mapped on table. You can define custom mappings in writer settings.

Available settings:
  • ChannelTableTemplate - template for table name. It is used for all channels that does not have specific mapping. In the template you can use special parameters:
    • {ChannelName} - will be replaced with name of the channel.
  • ConnectionString - database connection string.
  • Timeout - timeout of data writing. Measured in seconds. Default value - 4 minutes.
  • Mappings - special mappings configuration. Mapping value - special table name template. You can use same parameters as for ChannelTableTemplate.

Configuration samples.

For example we define two channels:
  • Information - channel for some information messages.
  • Exception - channel for errors information.

We want write data from Information channel to table InfoLog.
Other tables should have name like <ChannelName>Log.

There is configuration:
<add id="1" type="NSoft.Log.Writers.DB.DBLogWriter, NSoft.Log.Writers" configurationType="NSoft.Log.Writers.DB.DBLogWriterSettings, NSoft.Log.Writers">
  <configuration>
    <channelTableTemplate>{ChannelName}Log</channelTableTemplate>
    <connectionString>Data Source=.;Initial Catalog=Log;Integrated Security=SSPI;</connectionString>
    <Timeout>60</Timeout>

    <mappings>
      <add channelName="Information " value="InfoLog"/>
    </mappings>
  </configuration>
</add>

Last edited Apr 2, 2011 at 6:53 AM by Tesh, version 2