Skip to content

Commit 2f51d54

Browse files
author
Kadluba Christian
committed
* Made interface change non-breaking (new default parameter logEventFormatter moved to last position).
* Completed merged from upstream serilog/dev.
1 parent 5df870f commit 2f51d54

File tree

9 files changed

+48
-54
lines changed

9 files changed

+48
-54
lines changed

src/Serilog.Sinks.MSSqlServer/Configuration/Extensions/Hybrid/LoggerConfigurationMSSqlServerExtensions.cs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,11 @@ public static class LoggerConfigurationMSSqlServerExtensions
5151
/// <param name="batchPostingLimit">The maximum number of events to post in a single batch.</param>
5252
/// <param name="period">The time to wait between checking for event batches.</param>
5353
/// <param name="formatProvider">Supplies culture-specific formatting information, or null.</param>
54-
/// <param name="logEventFormatter">Supplies custom formatter for the LogEvent column, or null</param>
5554
/// <param name="autoCreateSqlTable">Create log table with the provided name on destination sql server.</param>
5655
/// <param name="columnOptions">An externally-modified group of column settings</param>
5756
/// <param name="columnOptionsSection">A config section defining various column settings</param>
5857
/// <param name="schemaName">Name of the schema for the table to store the data in. The default is 'dbo'.</param>
58+
/// <param name="logEventFormatter">Supplies custom formatter for the LogEvent column, or null</param>
5959
/// <returns>Logger configuration, allowing configuration to continue.</returns>
6060
/// <exception cref="ArgumentNullException">A required parameter is null.</exception>
6161
public static LoggerConfiguration MSSqlServer(
@@ -67,11 +67,11 @@ public static LoggerConfiguration MSSqlServer(
6767
int batchPostingLimit = MSSqlServerSink.DefaultBatchPostingLimit,
6868
TimeSpan? period = null,
6969
IFormatProvider formatProvider = null,
70-
ITextFormatter logEventFormatter = null,
7170
bool autoCreateSqlTable = false,
7271
ColumnOptions columnOptions = null,
7372
IConfigurationSection columnOptionsSection = null,
74-
string schemaName = "dbo")
73+
string schemaName = "dbo",
74+
ITextFormatter logEventFormatter = null)
7575
{
7676
if (loggerConfiguration == null)
7777
throw new ArgumentNullException(nameof(loggerConfiguration));
@@ -102,11 +102,10 @@ public static LoggerConfiguration MSSqlServer(
102102
batchPostingLimit,
103103
defaultedPeriod,
104104
formatProvider,
105-
logEventFormatter,
106105
autoCreateSqlTable,
107106
colOpts,
108-
schemaName
109-
),
107+
schemaName,
108+
logEventFormatter),
110109
restrictedToMinimumLevel);
111110
}
112111

@@ -119,11 +118,11 @@ public static LoggerConfiguration MSSqlServer(
119118
/// <param name="appConfiguration">Additional application-level configuration. Required if connectionString is a name.</param>
120119
/// <param name="restrictedToMinimumLevel">The minimum log event level required in order to write an event to the sink.</param>
121120
/// <param name="formatProvider">Supplies culture-specific formatting information, or null.</param>
122-
/// <param name="logEventFormatter">Supplies custom formatter for the LogEvent column, or null</param>
123121
/// <param name="autoCreateSqlTable">Create log table with the provided name on destination sql server.</param>
124122
/// <param name="columnOptions">An externally-modified group of column settings</param>
125123
/// <param name="columnOptionsSection">A config section defining various column settings</param>
126124
/// <param name="schemaName">Name of the schema for the table to store the data in. The default is 'dbo'.</param>
125+
/// <param name="logEventFormatter">Supplies custom formatter for the LogEvent column, or null</param>
127126
/// <returns>Logger configuration, allowing configuration to continue.</returns>
128127
/// <exception cref="ArgumentNullException">A required parameter is null.</exception>
129128
public static LoggerConfiguration MSSqlServer(
@@ -133,11 +132,11 @@ public static LoggerConfiguration MSSqlServer(
133132
IConfiguration appConfiguration = null,
134133
LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum,
135134
IFormatProvider formatProvider = null,
136-
ITextFormatter logEventFormatter = null,
137135
bool autoCreateSqlTable = false,
138136
ColumnOptions columnOptions = null,
139137
IConfigurationSection columnOptionsSection = null,
140-
string schemaName = "dbo")
138+
string schemaName = "dbo",
139+
ITextFormatter logEventFormatter = null)
141140
{
142141
if (loggerAuditSinkConfiguration == null)
143142
throw new ArgumentNullException(nameof(loggerAuditSinkConfiguration));
@@ -165,11 +164,10 @@ public static LoggerConfiguration MSSqlServer(
165164
connStr,
166165
tableName,
167166
formatProvider,
168-
logEventFormatter,
169167
autoCreateSqlTable,
170168
colOpts,
171-
schemaName
172-
),
169+
schemaName,
170+
logEventFormatter),
173171
restrictedToMinimumLevel);
174172
}
175173
}

src/Serilog.Sinks.MSSqlServer/Configuration/Extensions/Microsoft.Extensions.Configuration/LoggerConfigurationMSSqlServerExtensions.cs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,11 @@ public static partial class LoggerConfigurationMSSqlServerExtensions
4242
/// <param name="batchPostingLimit">The maximum number of events to post in a single batch.</param>
4343
/// <param name="period">The time to wait between checking for event batches.</param>
4444
/// <param name="formatProvider">Supplies culture-specific formatting information, or null.</param>
45-
/// <param name="logEventFormatter">Supplies custom formatter for the LogEvent column, or null</param>
4645
/// <param name="autoCreateSqlTable">Create log table with the provided name on destination sql server.</param>
4746
/// <param name="columnOptions">An externally-modified group of column settings</param>
4847
/// <param name="columnOptionsSection">A config section defining various column settings</param>
4948
/// <param name="schemaName">Name of the schema for the table to store the data in. The default is 'dbo'.</param>
49+
/// <param name="logEventFormatter">Supplies custom formatter for the LogEvent column, or null</param>
5050
/// <returns>Logger configuration, allowing configuration to continue.</returns>
5151
/// <exception cref="ArgumentNullException">A required parameter is null.</exception>
5252
public static LoggerConfiguration MSSqlServer(
@@ -58,11 +58,11 @@ public static LoggerConfiguration MSSqlServer(
5858
int batchPostingLimit = MSSqlServerSink.DefaultBatchPostingLimit,
5959
TimeSpan? period = null,
6060
IFormatProvider formatProvider = null,
61-
ITextFormatter logEventFormatter = null,
6261
bool autoCreateSqlTable = false,
6362
ColumnOptions columnOptions = null,
6463
IConfigurationSection columnOptionsSection = null,
65-
string schemaName = "dbo")
64+
string schemaName = "dbo",
65+
ITextFormatter logEventFormatter = null)
6666
{
6767
if (loggerConfiguration == null)
6868
throw new ArgumentNullException(nameof(loggerConfiguration));
@@ -78,11 +78,10 @@ public static LoggerConfiguration MSSqlServer(
7878
batchPostingLimit,
7979
defaultedPeriod,
8080
formatProvider,
81-
logEventFormatter,
8281
autoCreateSqlTable,
8382
colOpts,
84-
schemaName
85-
),
83+
schemaName,
84+
logEventFormatter),
8685
restrictedToMinimumLevel);
8786
}
8887

@@ -95,11 +94,11 @@ public static LoggerConfiguration MSSqlServer(
9594
/// <param name="appConfiguration">Additional application-level configuration. Required if connectionString is a name.</param>
9695
/// <param name="restrictedToMinimumLevel">The minimum log event level required in order to write an event to the sink.</param>
9796
/// <param name="formatProvider">Supplies culture-specific formatting information, or null.</param>
98-
/// <param name="logEventFormatter">Supplies custom formatter for the LogEvent column, or null</param>
9997
/// <param name="autoCreateSqlTable">Create log table with the provided name on destination sql server.</param>
10098
/// <param name="columnOptions">An externally-modified group of column settings</param>
10199
/// <param name="columnOptionsSection">A config section defining various column settings</param>
102100
/// <param name="schemaName">Name of the schema for the table to store the data in. The default is 'dbo'.</param>
101+
/// <param name="logEventFormatter">Supplies custom formatter for the LogEvent column, or null</param>
103102
/// <returns>Logger configuration, allowing configuration to continue.</returns>
104103
/// <exception cref="ArgumentNullException">A required parameter is null.</exception>
105104
public static LoggerConfiguration MSSqlServer(
@@ -109,11 +108,11 @@ public static LoggerConfiguration MSSqlServer(
109108
IConfiguration appConfiguration = null,
110109
LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum,
111110
IFormatProvider formatProvider = null,
112-
ITextFormatter logEventFormatter = null,
113111
bool autoCreateSqlTable = false,
114112
ColumnOptions columnOptions = null,
115113
IConfigurationSection columnOptionsSection = null,
116-
string schemaName = "dbo")
114+
string schemaName = "dbo",
115+
ITextFormatter logEventFormatter = null)
117116
{
118117
if (loggerAuditSinkConfiguration == null)
119118
throw new ArgumentNullException(nameof(loggerAuditSinkConfiguration));
@@ -126,10 +125,10 @@ public static LoggerConfiguration MSSqlServer(
126125
connectionString,
127126
tableName,
128127
formatProvider,
129-
logEventFormatter,
130128
autoCreateSqlTable,
131129
columnOptions,
132-
schemaName),
130+
schemaName,
131+
logEventFormatter),
133132
restrictedToMinimumLevel);
134133
}
135134
}

src/Serilog.Sinks.MSSqlServer/Configuration/Extensions/System.Configuration/LoggerConfigurationMSSqlServerExtensions.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ public static class LoggerConfigurationMSSqlServerExtensions
4747
/// <param name="batchPostingLimit">The maximum number of events to post in a single batch.</param>
4848
/// <param name="period">The time to wait between checking for event batches.</param>
4949
/// <param name="formatProvider">Supplies culture-specific formatting information, or null.</param>
50-
/// <param name="logEventFormatter">Supplies custom formatter for the LogEvent column, or null</param>
5150
/// <param name="autoCreateSqlTable">Create log table with the provided name on destination sql server.</param>
5251
/// <param name="columnOptions"></param>
52+
/// <param name="logEventFormatter">Supplies custom formatter for the LogEvent column, or null</param>
5353
/// <returns>Logger configuration, allowing configuration to continue.</returns>
5454
/// <exception cref="ArgumentNullException">A required parameter is null.</exception>
5555
public static LoggerConfiguration MSSqlServer(
@@ -60,10 +60,10 @@ public static LoggerConfiguration MSSqlServer(
6060
int batchPostingLimit = MSSqlServerSink.DefaultBatchPostingLimit,
6161
TimeSpan? period = null,
6262
IFormatProvider formatProvider = null,
63-
ITextFormatter logEventFormatter = null,
6463
bool autoCreateSqlTable = false,
6564
ColumnOptions columnOptions = null,
66-
string schemaName = "dbo")
65+
string schemaName = "dbo",
66+
ITextFormatter logEventFormatter = null)
6767
{
6868
if (loggerConfiguration == null)
6969
throw new ArgumentNullException(nameof(loggerConfiguration));
@@ -83,10 +83,10 @@ public static LoggerConfiguration MSSqlServer(
8383
batchPostingLimit,
8484
defaultedPeriod,
8585
formatProvider,
86-
logEventFormatter,
8786
autoCreateSqlTable,
8887
colOpts,
89-
schemaName),
88+
schemaName,
89+
logEventFormatter),
9090
restrictedToMinimumLevel);
9191
}
9292

@@ -102,9 +102,9 @@ public static LoggerConfiguration MSSqlServer(
102102
/// <param name="schemaName">Name of the schema for the table to store the data in. The default is 'dbo'.</param>
103103
/// <param name="restrictedToMinimumLevel">The minimum log event level required in order to write an event to the sink.</param>
104104
/// <param name="formatProvider">Supplies culture-specific formatting information, or null.</param>
105-
/// <param name="logEventFormatter">Supplies custom formatter for the LogEvent column, or null</param>
106105
/// <param name="autoCreateSqlTable">Create log table with the provided name on destination sql server.</param>
107106
/// <param name="columnOptions"></param>
107+
/// <param name="logEventFormatter">Supplies custom formatter for the LogEvent column, or null</param>
108108
/// <returns>Logger configuration, allowing configuration to continue.</returns>
109109
/// <exception cref="ArgumentNullException">A required parameter is null.</exception>
110110
public static LoggerConfiguration MSSqlServer(
@@ -113,10 +113,10 @@ public static LoggerConfiguration MSSqlServer(
113113
string tableName,
114114
LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum,
115115
IFormatProvider formatProvider = null,
116-
ITextFormatter logEventFormatter = null,
117116
bool autoCreateSqlTable = false,
118117
ColumnOptions columnOptions = null,
119-
string schemaName = "dbo")
118+
string schemaName = "dbo",
119+
ITextFormatter logEventFormatter = null)
120120
{
121121
if (loggerAuditSinkConfiguration == null)
122122
throw new ArgumentNullException(nameof(loggerAuditSinkConfiguration));
@@ -133,10 +133,10 @@ public static LoggerConfiguration MSSqlServer(
133133
connectionString,
134134
tableName,
135135
formatProvider,
136-
logEventFormatter,
137136
autoCreateSqlTable,
138137
colOpts,
139-
schemaName),
138+
schemaName,
139+
logEventFormatter),
140140
restrictedToMinimumLevel);
141141
}
142142
}

src/Serilog.Sinks.MSSqlServer/Sinks/MSSqlServer/MSSqlServerAuditSink.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,18 +38,17 @@ public class MSSqlServerAuditSink : ILogEventSink, IDisposable
3838
/// <param name="tableName">Name of the table to store the data in.</param>
3939
/// <param name="schemaName">Name of the schema for the table to store the data in. The default is 'dbo'.</param>
4040
/// <param name="formatProvider">Supplies culture-specific formatting information, or null.</param>
41-
/// <param name="logEventFormatter">Supplies custom formatter for the LogEvent column, or null</param>
4241
/// <param name="autoCreateSqlTable">Create log table with the provided name on destination sql server.</param>
4342
/// <param name="columnOptions">Options that pertain to columns</param>
43+
/// <param name="logEventFormatter">Supplies custom formatter for the LogEvent column, or null</param>
4444
public MSSqlServerAuditSink(
4545
string connectionString,
4646
string tableName,
4747
IFormatProvider formatProvider,
48-
ITextFormatter logEventFormatter = null,
4948
bool autoCreateSqlTable = false,
5049
ColumnOptions columnOptions = null,
51-
string schemaName = "dbo"
52-
)
50+
string schemaName = "dbo",
51+
ITextFormatter logEventFormatter = null)
5352
{
5453
columnOptions.FinalizeConfigurationForSinkConstructor();
5554

@@ -59,7 +58,7 @@ public MSSqlServerAuditSink(
5958
throw new NotSupportedException($"The {nameof(ColumnOptions.DisableTriggers)} option is not supported for auditing.");
6059
}
6160

62-
_traits = new MSSqlServerSinkTraits(connectionString, tableName, schemaName, columnOptions, formatProvider, logEventFormatter, autoCreateSqlTable);
61+
_traits = new MSSqlServerSinkTraits(connectionString, tableName, schemaName, columnOptions, formatProvider, autoCreateSqlTable, logEventFormatter);
6362

6463
}
6564

src/Serilog.Sinks.MSSqlServer/Sinks/MSSqlServer/MSSqlServerSink.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,24 +52,23 @@ public class MSSqlServerSink : PeriodicBatchingSink
5252
/// <param name="batchPostingLimit">The maximum number of events to post in a single batch.</param>
5353
/// <param name="period">The time to wait between checking for event batches.</param>
5454
/// <param name="formatProvider">Supplies culture-specific formatting information, or null.</param>
55-
/// <param name="logEventFormatter">Supplies custom formatter for the LogEvent column, or null</param>
5655
/// <param name="autoCreateSqlTable">Create log table with the provided name on destination sql server.</param>
5756
/// <param name="columnOptions">Options that pertain to columns</param>
57+
/// <param name="logEventFormatter">Supplies custom formatter for the LogEvent column, or null</param>
5858
public MSSqlServerSink(
5959
string connectionString,
6060
string tableName,
6161
int batchPostingLimit,
6262
TimeSpan period,
6363
IFormatProvider formatProvider,
64-
ITextFormatter logEventFormatter = null,
6564
bool autoCreateSqlTable = false,
6665
ColumnOptions columnOptions = null,
67-
string schemaName = "dbo"
68-
)
66+
string schemaName = "dbo",
67+
ITextFormatter logEventFormatter = null)
6968
: base(batchPostingLimit, period)
7069
{
7170
columnOptions.FinalizeConfigurationForSinkConstructor();
72-
_traits = new MSSqlServerSinkTraits(connectionString, tableName, schemaName, columnOptions, formatProvider, logEventFormatter, autoCreateSqlTable);
71+
_traits = new MSSqlServerSinkTraits(connectionString, tableName, schemaName, columnOptions, formatProvider, autoCreateSqlTable, logEventFormatter);
7372
}
7473

7574
/// <summary>

src/Serilog.Sinks.MSSqlServer/Sinks/MSSqlServer/MSSqlServerSinkTraits.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
using System.Linq;
2424
using System.Text;
2525

26-
2726
namespace Serilog.Sinks.MSSqlServer
2827
{
2928
/// <summary>Contains common functionality and properties used by both MSSqlServerSinks.</summary>
@@ -45,8 +44,8 @@ public MSSqlServerSinkTraits(
4544
string schemaName,
4645
ColumnOptions columnOptions,
4746
IFormatProvider formatProvider,
48-
ITextFormatter logEventFormatter,
49-
bool autoCreateSqlTable)
47+
bool autoCreateSqlTable,
48+
ITextFormatter logEventFormatter)
5049
{
5150
if (string.IsNullOrWhiteSpace(connectionString))
5251
throw new ArgumentNullException(nameof(connectionString));
@@ -151,7 +150,7 @@ private KeyValuePair<string, object> GetTimeStampStandardColumnNameAndValue(LogE
151150
return new KeyValuePair<string, object>(columnOptions.TimeStamp.ColumnName, dateTimeOffset.DateTime);
152151
}
153152

154-
private string LogEventToJson(LogEvent logEvent)
153+
private string RenderLogEventColumn(LogEvent logEvent)
155154
{
156155
if (columnOptions.LogEvent.ExcludeAdditionalProperties)
157156
{

0 commit comments

Comments
 (0)