@@ -48,6 +48,7 @@ public class MSSqlServerSink : PeriodicBatchingSink
48
48
readonly DataTable _eventsTable ;
49
49
readonly IFormatProvider _formatProvider ;
50
50
readonly string _tableName ;
51
+ readonly string _schemaName ;
51
52
private readonly ColumnOptions _columnOptions ;
52
53
53
54
private readonly HashSet < string > _additionalDataColumnNames ;
@@ -60,6 +61,7 @@ public class MSSqlServerSink : PeriodicBatchingSink
60
61
/// </summary>
61
62
/// <param name="connectionString">Connection string to access the database.</param>
62
63
/// <param name="tableName">Name of the table to store the data in.</param>
64
+ /// <param name="schemaName">Name of the schema for the table to store the data in. The default is 'dbo'.</param>
63
65
/// <param name="batchPostingLimit">The maximum number of events to post in a single batch.</param>
64
66
/// <param name="period">The time to wait between checking for event batches.</param>
65
67
/// <param name="formatProvider">Supplies culture-specific formatting information, or null.</param>
@@ -72,7 +74,8 @@ public MSSqlServerSink(
72
74
TimeSpan period ,
73
75
IFormatProvider formatProvider ,
74
76
bool autoCreateSqlTable = false ,
75
- ColumnOptions columnOptions = null
77
+ ColumnOptions columnOptions = null ,
78
+ string schemaName = "dbo"
76
79
)
77
80
: base ( batchPostingLimit , period )
78
81
{
@@ -84,6 +87,7 @@ public MSSqlServerSink(
84
87
85
88
_connectionString = connectionString ;
86
89
_tableName = tableName ;
90
+ _schemaName = schemaName ;
87
91
_formatProvider = formatProvider ;
88
92
_columnOptions = columnOptions ?? new ColumnOptions ( ) ;
89
93
if ( _columnOptions . AdditionalDataColumns != null )
@@ -99,7 +103,7 @@ public MSSqlServerSink(
99
103
{
100
104
try
101
105
{
102
- SqlTableCreator tableCreator = new SqlTableCreator ( connectionString ) ;
106
+ SqlTableCreator tableCreator = new SqlTableCreator ( connectionString , _schemaName ) ;
103
107
tableCreator . CreateTable ( _eventsTable ) ;
104
108
}
105
109
catch ( Exception ex )
@@ -134,7 +138,7 @@ protected override async Task EmitBatchAsync(IEnumerable<LogEvent> events)
134
138
: new SqlBulkCopy ( cn , SqlBulkCopyOptions . CheckConstraints | SqlBulkCopyOptions . FireTriggers , null )
135
139
)
136
140
{
137
- copy . DestinationTableName = _tableName ;
141
+ copy . DestinationTableName = string . Format ( "[{0}].[{1}]" , _schemaName , _tableName ) ;
138
142
foreach ( var column in _eventsTable . Columns )
139
143
{
140
144
var columnName = ( ( DataColumn ) column ) . ColumnName ;
0 commit comments