src/Serilog.Sinks.MSSqlServer/Sinks/MSSqlServer/MSSqlServerSink.cs
/// <summary>
///     Emit a batch of log events, running asynchronously.
/// </summary>
/// <param name="events">The events to emit.</param>
/// <remarks>
///     Override either <see cref="PeriodicBatchingSink.EmitBatch" /> or <see cref="PeriodicBatchingSink.EmitBatchAsync" />
///     ,
///     not both.
/// </remarks>
Emit a batch of log events, running asynchronously.
Emit a batch of log events running asynchronously .
protected override async Task EmitBatchAsync(IEnumerable<LogEvent> events)
        {
            FillDataTable(events);
            try
            {
                using (var cn = _sqlConnectionFactory.Create())
                {
                    await cn.OpenAsync().ConfigureAwait(false);
                    using (var copy = _traits.ColumnOptions.DisableTriggers
                            ? new SqlBulkCopy(cn)
                            : new SqlBulkCopy(cn, SqlBulkCopyOptions.CheckConstraints | SqlBulkCopyOptions.FireTriggers, null)
                    )
                    {
                        copy.DestinationTableName = string.Format(CultureInfo.InvariantCulture, "[{0}].[{1}]", _traits.SchemaName, _traits.TableName);
                        foreach (var column in _traits.EventTable.Columns)
                        {
                            var columnName = ((DataColumn)column).ColumnName;
                            var mapping = new SqlBulkCopyColumnMapping(columnName, columnName);
                            copy.ColumnMappings.Add(mapping);
                        }
                        await copy.WriteToServerAsync(_traits.EventTable).ConfigureAwait(false);
                    }
                }
            }
            catch (Exception ex)
            {
                SelfLog.WriteLine("Unable to write {0} log events to the database due to following error: {1}", events.Count(), ex.Message);
            }
            finally
            {
                _traits.EventTable.Clear();
            }
        }
protected override async Task EmitBatchAsync ( IEnumerable < LogEvent > events ) { FillDataTable ( events ) ; try { using ( var cn = _sqlConnectionFactory . Create ( ) ) { await cn . OpenAsync ( ) . ConfigureAwait ( false ) ; using ( var copy = _traits . ColumnOptions . DisableTriggers ? new SqlBulkCopy ( cn ) : new SqlBulkCopy ( cn , SqlBulkCopyOptions . CheckConstraints | SqlBulkCopyOptions . FireTriggers , null ) ) { copy . DestinationTableName = string . Format ( CultureInfo . InvariantCulture , " " , _traits . SchemaName , _traits . TableName ) ; foreach ( var column in _traits . EventTable . Columns ) { var columnName = ( ( DataColumn ) column ) . ColumnName ; var mapping = new SqlBulkCopyColumnMapping ( columnName , columnName ) ; copy . ColumnMappings . Add ( mapping ) ; } await copy . WriteToServerAsync ( _traits . EventTable ) . ConfigureAwait ( false ) ; } } } catch ( Exception ex ) { SelfLog . WriteLine ( " " , events . Count ( ) , ex . Message ) ; } finally { _traits . EventTable . Clear ( ) ; } }
Emit a batch of log events, running asynchronously.
Emit a batch of log events running asynchronously .
// Copy the events to the data table // Processed the items, clear for the next run
events
IEnumerable<LogEvent>
The events to emit.
The events to emit .
remarks
Override either  or
,
not both.
Override either or not both .