Skip to content

Commit 354c4be

Browse files
committed
* Added a working and non-working initializer code to the NetStandardDemo regarding issue 290 (MissingMethodException).
* Reordered parameters in M.E.C. config extensions to match hybrid variant of the methods.
1 parent fcd389c commit 354c4be

File tree

2 files changed

+36
-11
lines changed

2 files changed

+36
-11
lines changed

sample/NetStandardDemo/NetStandardDemoLib/Initializer.cs

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System.Collections.ObjectModel;
22
using System.Data;
33
using Serilog;
4+
using Serilog.Events;
45
using Serilog.Sinks.MSSqlServer;
56
using Serilog.Sinks.MSSqlServer.Sinks.MSSqlServer.Options;
67

@@ -13,6 +14,7 @@ public static class Initializer
1314

1415
public static LoggerConfiguration CreateLoggerConfiguration()
1516
{
17+
// Error MissingMethodException
1618
return new LoggerConfiguration()
1719
.Enrich.FromLogContext()
1820
.WriteTo.MSSqlServer(
@@ -22,7 +24,30 @@ public static LoggerConfiguration CreateLoggerConfiguration()
2224
TableName = _tableName,
2325
AutoCreateSqlTable = true
2426
},
25-
columnOptions: BuildColumnOptions());
27+
appConfiguration: null,
28+
sinkOptionsSection: null,
29+
restrictedToMinimumLevel: LevelAlias.Minimum,
30+
formatProvider: null,
31+
columnOptions: BuildColumnOptions(),
32+
columnOptionsSection: null,
33+
logEventFormatter: null);
34+
35+
// Works
36+
//return new LoggerConfiguration()
37+
// .Enrich.FromLogContext()
38+
// .WriteTo.MSSqlServer(
39+
// _connectionString,
40+
// tableName: _tableName,
41+
// appConfiguration: null,
42+
// restrictedToMinimumLevel: LevelAlias.Minimum,
43+
// batchPostingLimit: MSSqlServerSink.DefaultBatchPostingLimit,
44+
// period: null,
45+
// formatProvider: null,
46+
// autoCreateSqlTable: true,
47+
// columnOptions: BuildColumnOptions(),
48+
// columnOptionsSection: null,
49+
// schemaName: MSSqlServerSink.DefaultSchemaName,
50+
// logEventFormatter: null);
2651
}
2752

2853
private static ColumnOptions BuildColumnOptions()

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,12 @@ public static LoggerConfiguration MSSqlServer(
7979
connectionString: connectionString,
8080
sinkOptions: sinkOptions,
8181
appConfiguration: appConfiguration,
82+
sinkOptionsSection: null,
8283
restrictedToMinimumLevel: restrictedToMinimumLevel,
8384
formatProvider: formatProvider,
8485
columnOptions: columnOptions,
8586
columnOptionsSection: columnOptionsSection,
86-
logEventFormatter: logEventFormatter,
87-
sinkOptionsSection: null);
87+
logEventFormatter: logEventFormatter);
8888
}
8989

9090
/// <summary>
@@ -97,25 +97,25 @@ public static LoggerConfiguration MSSqlServer(
9797
/// <param name="connectionString">The connection string to the database where to store the events.</param>
9898
/// <param name="sinkOptions">Supplies additional settings for the sink</param>
9999
/// <param name="appConfiguration">Additional application-level configuration. Required if connectionString is a name.</param>
100+
/// <param name="sinkOptionsSection">A config section defining additional settings for the sink</param>
100101
/// <param name="restrictedToMinimumLevel">The minimum log event level required in order to write an event to the sink.</param>
101102
/// <param name="formatProvider">Supplies culture-specific formatting information, or null.</param>
102103
/// <param name="columnOptions">An externally-modified group of column settings</param>
103104
/// <param name="columnOptionsSection">A config section defining various column settings</param>
104105
/// <param name="logEventFormatter">Supplies custom formatter for the LogEvent column, or null</param>
105-
/// <param name="sinkOptionsSection">A config section defining additional settings for the sink</param>
106106
/// <returns>Logger configuration, allowing configuration to continue.</returns>
107107
/// <exception cref="ArgumentNullException">A required parameter is null.</exception>
108108
public static LoggerConfiguration MSSqlServer(
109109
this LoggerSinkConfiguration loggerConfiguration,
110110
string connectionString,
111111
SinkOptions sinkOptions = null,
112112
IConfiguration appConfiguration = null,
113+
IConfigurationSection sinkOptionsSection = null,
113114
LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum,
114115
IFormatProvider formatProvider = null,
115116
ColumnOptions columnOptions = null,
116117
IConfigurationSection columnOptionsSection = null,
117-
ITextFormatter logEventFormatter = null,
118-
IConfigurationSection sinkOptionsSection = null)
118+
ITextFormatter logEventFormatter = null)
119119
{
120120
if (loggerConfiguration == null)
121121
throw new ArgumentNullException(nameof(loggerConfiguration));
@@ -171,12 +171,12 @@ public static LoggerConfiguration MSSqlServer(
171171
connectionString: connectionString,
172172
sinkOptions: sinkOptions,
173173
appConfiguration: appConfiguration,
174+
sinkOptionsSection: null,
174175
restrictedToMinimumLevel: restrictedToMinimumLevel,
175176
formatProvider: formatProvider,
176177
columnOptions: columnOptions,
177178
columnOptionsSection: columnOptionsSection,
178-
logEventFormatter: logEventFormatter,
179-
sinkOptionsSection: null);
179+
logEventFormatter: logEventFormatter);
180180
}
181181

182182
/// <summary>
@@ -186,25 +186,25 @@ public static LoggerConfiguration MSSqlServer(
186186
/// <param name="connectionString">The connection string to the database where to store the events.</param>
187187
/// <param name="sinkOptions">Supplies additional settings for the sink</param>
188188
/// <param name="appConfiguration">Additional application-level configuration. Required if connectionString is a name.</param>
189+
/// <param name="sinkOptionsSection">A config section defining additional settings for the sink</param>
189190
/// <param name="restrictedToMinimumLevel">The minimum log event level required in order to write an event to the sink.</param>
190191
/// <param name="formatProvider">Supplies culture-specific formatting information, or null.</param>
191192
/// <param name="columnOptions">An externally-modified group of column settings</param>
192193
/// <param name="columnOptionsSection">A config section defining various column settings</param>
193194
/// <param name="logEventFormatter">Supplies custom formatter for the LogEvent column, or null</param>
194-
/// <param name="sinkOptionsSection">A config section defining additional settings for the sink</param>
195195
/// <returns>Logger configuration, allowing configuration to continue.</returns>
196196
/// <exception cref="ArgumentNullException">A required parameter is null.</exception>
197197
public static LoggerConfiguration MSSqlServer(
198198
this LoggerAuditSinkConfiguration loggerAuditSinkConfiguration,
199199
string connectionString,
200200
SinkOptions sinkOptions = null,
201201
IConfiguration appConfiguration = null,
202+
IConfigurationSection sinkOptionsSection = null,
202203
LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum,
203204
IFormatProvider formatProvider = null,
204205
ColumnOptions columnOptions = null,
205206
IConfigurationSection columnOptionsSection = null,
206-
ITextFormatter logEventFormatter = null,
207-
IConfigurationSection sinkOptionsSection = null)
207+
ITextFormatter logEventFormatter = null)
208208
{
209209
if (loggerAuditSinkConfiguration == null)
210210
throw new ArgumentNullException(nameof(loggerAuditSinkConfiguration));

0 commit comments

Comments
 (0)