Delen via


Event Collection Bulk Copy Interface

AppFabric provides a default bulk copy provider for SQL Server that provides better performance when writing large amounts of event data to the monitoring store. However, you may be storing your event monitoring data in a non-SQL Server store. In this case you will need to develop a database-specific bulk copy provider to support bulk copying of event data to your non-SQL Server store. If a suitable bulk copy plug-in has not been registered for a specific data store, the Event Collection service reverts to the ADO.NET batch insert mode to write events to the monitoring store.

To create a database-specific bulk copy provider, your .NET Framework 4 object class implements the Microsoft.ApplicationServer.Monitoring.EventCollector.IBulkCopy interface as part of the bulk copy provider’s functionality. You then register the provider in the root Web.config file. Registering your bulk copy provider tells the Event Collection service to invoke the provider’s IBulkCopy interface when it needs to write events to the store. Only the Event Collection service can access this interface programmatically. When it is invoked, the bulk copy provider transfers large amounts of cached event data from an Event Tracing for Windows (ETW) session to the monitoring store.

Configuring a Bulk Copy Provider

Here is an example of how the default SQL Server bulk copy provider, System.Data.SqlClient, that AppFabric provides is registered with the Event Collection service. You would register your database-specific bulk copy provider in a similar way.

<microsoft.applicationServer>
  <monitoring lockElements="bulkCopyProviders, collectors">
    <bulkCopyProviders>
        <bulkCopyProvider providerName="System.Data.SqlClient" type="Microsoft.ApplicationServer.Monitoring.EventCollector.SqlServerBulkCopy, Microsoft.ApplicationServer.Monitoring, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
        </bulkCopyProviders>
    <collectors>
        <collector name="" session="0">
        <settings retryCount="10" eventBufferSize="10000" retryWait="00:00:15" maxWriteDelay="00:00:05" />
        </collector>
    </collectors>
    <default enabled="true" connectionStringName="DefaultMonitoringConnectionString" monitoringLevel="HealthMonitoring" />
  </monitoring>
</microsoft.applicationServer>
    
<connectionStrings>
    <add connectionString="Data Source=localhost;Initial Catalog=ApplicationServerMonitoring;Integrated Security=True" name="DefaultPersistenceConnectionString" providerName="System.Data.SqlClient" />
    <add connectionString="Data Source=localhost;Initial Catalog=ApplicationServerMonitoring;Integrated Security=True" name="DefaultMonitoringConnectionString" providerName="System.Data.SqlClient" />
</connectionStrings>

Microsoft.ApplicationServer.Monitoring.EventCollector.SqlServerBulkCopy is the type of the provider class that implements the IBulkCopy interface. The bulk copy operation occurs when either of the following conditions is met:

  • The number of events in the Event Collection service event buffer exceeds the eventBufferSize attribute. In this example, it is set to write when the 10,000-event limit has been reached.

  • The time interval has expired in the maxWriteDelay attribute. In this example, it is set to write every 5 seconds.

For more information about how to configure the Event Collection service and a bulk copy provider, refer to Configure the Event Collection Service.

Microsoft.ApplicationServer.Monitoring.EventCollector.IBulkCopy (Interface)

Here is a definition of the IBulkCopy interface. You would implement the WriteServer method to handle the database-specific task of writing event data using your database-specific provider class.

Namespace: Microsoft.ApplicationServer.Monitoring.EventCollector
namespace Microsoft.ApplicationServer.Monitoring.EventCollector
{
    using System;
    using System.Data;
    using System.Data.Common;


    public interface IBulkCopy
    {
        //Number of rows in each batch. At the end of each batch, the rows in the batch are written to store
        int BatchSize { get; set; }
      
        //The destination table name in the store to write the rows
        string DestinationTableName { get; set; }

        //The database connection to the store to which the rows are written
        DbConnection Connection { get; set; }

        //Copies all rows from the supplied IDataReader to the destination table specified by the DestinationTableName property, on the store specified by the Connection property
        void WriteToServer(IDataReader dataReader);
    }
}

For more information about the DataTable class, see DataTable Class (https://go.microsoft.com/fwlink/?LinkId=168571).