Skip to content

Commit cca2fc0

Browse files
authored
Merge pull request #134 from MV10/fix_level_colname_from_config
fixed copy-paste error that could set "Level" as the Id column name
2 parents 3fa70cd + 795ad03 commit cca2fc0

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ private static ColumnOptions ConfigureColumnOptions(ColumnOptions columnOptions,
221221
var section = config.GetSection("level");
222222
if(section.GetChildren().Any())
223223
{
224-
SetIfProvided<string>((val) => { opts.Id.ColumnName = val; }, section["columnName"]);
224+
SetIfProvided<string>((val) => { opts.Level.ColumnName = val; }, section["columnName"]);
225225
SetIfProvided<bool>((val) => { opts.Level.StoreAsEnum = val; }, section["storeAsEnum"]);
226226
}
227227

@@ -266,21 +266,21 @@ private static ColumnOptions ConfigureColumnOptions(ColumnOptions columnOptions,
266266

267267
return opts;
268268

269-
// this avoids changing the property if it isn't provided by config
269+
// This is used to only set a column property when it is actually specified in the config.
270+
// When a value is requested from config, it returns null if that value hasn't been specified.
271+
// This also means you can't use config to set a property to null.
270272
void SetIfProvided<T>(PropertySetter<T> setter, string value)
271273
{
272-
// note this means you can't use config to set a property to null
273274
if(value == null)
274275
return;
275276
try
276277
{
277278
var setting = (T)Convert.ChangeType(value, typeof(T));
278279
setter(setting);
279280
}
280-
catch
281-
{
282-
// don't change the property if the conversion failed
283-
}
281+
// don't change the property if the conversion failed
282+
catch (InvalidCastException) { }
283+
catch (OverflowException) { }
284284
}
285285
}
286286
}

0 commit comments

Comments
 (0)