Skip to content

Commit aa93ba3

Browse files
author
Colin Young
committed
Merge remote-tracking branch 'customid/IdColumnOptions' into localdb-tests
2 parents 03527ba + e69a199 commit aa93ba3

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/Serilog.Sinks.MSSqlServer/Sinks/MSSqlServer/ColumnOptions.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ public class ColumnOptions
1616
/// </summary>
1717
public ColumnOptions()
1818
{
19+
Id = new IdColumnOptions();
20+
1921
Level = new LevelColumnOptions();
2022

2123
Properties = new PropertiesColumnOptions();
@@ -63,6 +65,11 @@ public IDictionary<StandardColumn, string> Store
6365
/// </summary>
6466
public ICollection<DataColumn> AdditionalDataColumns { get; set; }
6567

68+
/// <summary>
69+
/// Options for the Id column.
70+
/// </summary>
71+
public IdColumnOptions Id { get; private set; }
72+
6673
/// <summary>
6774
/// Options for the Level column.
6875
/// </summary>
@@ -83,6 +90,17 @@ public IDictionary<StandardColumn, string> Store
8390
/// </summary>
8491
public LogEventColumnOptions LogEvent { get; private set; }
8592

93+
/// <summary>
94+
/// Options for the Id column.
95+
/// </summary>
96+
public class IdColumnOptions
97+
{
98+
/// <summary>
99+
/// The name of the Id column. "Id" is used if not set.
100+
/// </summary>
101+
public string ColumnName { get; set; }
102+
}
103+
86104
/// <summary>
87105
/// Options for the Level column.
88106
/// </summary>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ DataTable CreateDataTable()
163163
var id = new DataColumn
164164
{
165165
DataType = Type.GetType("System.Int32"),
166-
ColumnName = "Id",
166+
ColumnName = !string.IsNullOrWhiteSpace(_columnOptions.Id.ColumnName) ? _columnOptions.Id.ColumnName : "Id",
167167
AutoIncrement = true
168168
};
169169
eventsTable.Columns.Add(id);

0 commit comments

Comments
 (0)