Skip to content

Commit ec41352

Browse files
committed
Read new sink option PreventEnlistInTransaction from all supported configuration sources.
1 parent eacbca6 commit ec41352

File tree

5 files changed

+39
-0
lines changed

5 files changed

+39
-0
lines changed

src/Serilog.Sinks.MSSqlServer/Configuration/Implementations/Microsoft.Extensions.Configuration/MicrosoftExtensionsSinkOptionsProvider.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ private static void ReadTableOptions(IConfigurationSection config, MSSqlServerSi
2525
SetProperty.IfNotNull<string>(config["tableName"], val => sinkOptions.TableName = val);
2626
SetProperty.IfNotNull<string>(config["schemaName"], val => sinkOptions.SchemaName = val);
2727
SetProperty.IfNotNull<bool>(config["autoCreateSqlTable"], val => sinkOptions.AutoCreateSqlTable = val);
28+
SetProperty.IfNotNull<bool>(config["preventEnlistInTransaction"], val => sinkOptions.PreventEnlistInTransaction = val);
2829
}
2930

3031
private static void ReadBatchSettings(IConfigurationSection config, MSSqlServerSinkOptions sinkOptions)

src/Serilog.Sinks.MSSqlServer/Configuration/Implementations/System.Configuration/MSSqlServerConfigurationSection.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,12 @@ public ValueConfigElement AutoCreateSqlTable
157157
get => (ValueConfigElement)base[nameof(AutoCreateSqlTable)];
158158
}
159159

160+
[ConfigurationProperty(nameof(PreventEnlistInTransaction))]
161+
public ValueConfigElement PreventEnlistInTransaction
162+
{
163+
get => (ValueConfigElement)base[nameof(PreventEnlistInTransaction)];
164+
}
165+
160166
[ConfigurationProperty(nameof(BatchPostingLimit))]
161167
public ValueConfigElement BatchPostingLimit
162168
{

src/Serilog.Sinks.MSSqlServer/Configuration/Implementations/System.Configuration/SystemConfigurationSinkOptionsProvider.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ private static void ReadTableOptions(MSSqlServerConfigurationSection config, MSS
2121
SetProperty.IfProvided<string>(config.SchemaName, nameof(config.SchemaName.Value), value => sinkOptions.SchemaName = value);
2222
SetProperty.IfProvided<bool>(config.AutoCreateSqlTable, nameof(config.AutoCreateSqlTable.Value),
2323
value => sinkOptions.AutoCreateSqlTable = value);
24+
SetProperty.IfProvided<bool>(config.PreventEnlistInTransaction, nameof(config.PreventEnlistInTransaction.Value),
25+
value => sinkOptions.PreventEnlistInTransaction = value);
2426
}
2527

2628
private static void ReadBatchSettings(MSSqlServerConfigurationSection config, MSSqlServerSinkOptions sinkOptions)

test/Serilog.Sinks.MSSqlServer.Tests/Configuration/Implementations/Microsoft.Extensions.Configuration/MicrosoftExtensionsSinkOptionsProviderTests.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,20 @@ public void ConfigureSinkOptionsSetsAutoCreateSqlTable()
7676
Assert.True(result.AutoCreateSqlTable);
7777
}
7878

79+
[Fact]
80+
public void ConfigureSinkOptionsSetsPreventEnlistInTransaction()
81+
{
82+
// Arrange
83+
_configurationSectionMock.Setup(s => s["preventEnlistInTransaction"]).Returns("false");
84+
var sut = new MicrosoftExtensionsSinkOptionsProvider();
85+
86+
// Act
87+
var result = sut.ConfigureSinkOptions(new MSSqlServerSinkOptions(), _configurationSectionMock.Object);
88+
89+
// Assert
90+
Assert.False(result.PreventEnlistInTransaction);
91+
}
92+
7993
[Fact]
8094
public void ConfigureSinkOptionsSetsBatchPostingLimit()
8195
{

test/Serilog.Sinks.MSSqlServer.Tests/Configuration/Implementations/System.Configuration/SystemConfigurationSinkOptionsProviderTests.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,21 @@ public void ConfigureSinkOptionsReadsBatchSettings()
2323
// Assert
2424
Assert.True(sinkOptions.EagerlyEmitFirstEvent);
2525
}
26+
27+
[Fact]
28+
public void ConfigureSinkOptionsReadsPreventEnlistInTransaction()
29+
{
30+
// Arrange
31+
var configSection = new MSSqlServerConfigurationSection();
32+
configSection.PreventEnlistInTransaction.Value = "false";
33+
var sinkOptions = new MSSqlServerSinkOptions { PreventEnlistInTransaction = true };
34+
var sut = new SystemConfigurationSinkOptionsProvider();
35+
36+
// Act
37+
sut.ConfigureSinkOptions(configSection, sinkOptions);
38+
39+
// Assert
40+
Assert.False(sinkOptions.PreventEnlistInTransaction);
41+
}
2642
}
2743
}

0 commit comments

Comments
 (0)