Skip to content

Commit c6dbc1a

Browse files
authored
Merge pull request #38 from joe-perrin/dev
IdColumnOptions - allow a custom name to be specified for the `Id` column.
2 parents 1911cce + bf72f9f commit c6dbc1a

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
@@ -161,7 +161,7 @@ DataTable CreateDataTable()
161161
var id = new DataColumn
162162
{
163163
DataType = Type.GetType("System.Int32"),
164-
ColumnName = "Id",
164+
ColumnName = !string.IsNullOrWhiteSpace(_columnOptions.Id.ColumnName) ? _columnOptions.Id.ColumnName : "Id",
165165
AutoIncrement = true
166166
};
167167
eventsTable.Columns.Add(id);

0 commit comments

Comments
 (0)