Skip to content

Commit bf72f9f

Browse files
committed
Merge remote-tracking branch 'refs/remotes/origin/IdColumnOptions' into dev
2 parents f54daf7 + e69a199 commit bf72f9f

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
@@ -17,6 +17,8 @@ public class ColumnOptions
1717
/// </summary>
1818
public ColumnOptions()
1919
{
20+
Id = new IdColumnOptions();
21+
2022
Level = new LevelColumnOptions();
2123

2224
Properties = new PropertiesColumnOptions();
@@ -64,6 +66,11 @@ public ICollection<StandardColumn> Store
6466
/// </summary>
6567
public ICollection<DataColumn> AdditionalDataColumns { get; set; }
6668

69+
/// <summary>
70+
/// Options for the Id column.
71+
/// </summary>
72+
public IdColumnOptions Id { get; private set; }
73+
6774
/// <summary>
6875
/// Options for the Level column.
6976
/// </summary>
@@ -84,6 +91,17 @@ public ICollection<StandardColumn> Store
8491
/// </summary>
8592
public LogEventColumnOptions LogEvent { get; private set; }
8693

94+
/// <summary>
95+
/// Options for the Id column.
96+
/// </summary>
97+
public class IdColumnOptions
98+
{
99+
/// <summary>
100+
/// The name of the Id column. "Id" is used if not set.
101+
/// </summary>
102+
public string ColumnName { get; set; }
103+
}
104+
87105
/// <summary>
88106
/// Options for the Level column.
89107
/// </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)