Skip to content

Commit 3111f99

Browse files
committed
update xunit, convert DateTimeOffset to DateTime, handle custom column names
1 parent f983524 commit 3111f99

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

src/Serilog.Sinks.MSSqlServer/Sinks/MSSqlServer/MSSqlServerSinkTraits.cs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,14 @@ public MSSqlServerSinkTraits(string connectionString, string tableName, string s
5252
FormatProvider = formatProvider;
5353

5454
ExcludedColumnNames = new List<string>(ColumnOptions.Store.Count + 1);
55-
ExcludedColumnNames.Add("id");
56-
foreach (var column in ColumnOptions.Store)
57-
ExcludedColumnNames.Add(column.ToString());
55+
ExcludedColumnNames.Add(ColumnOptions.Id.ColumnName ?? "Id");
56+
if (ColumnOptions.Store.Contains(StandardColumn.Message)) ExcludedColumnNames.Add(ColumnOptions.Message.ColumnName ?? "Message");
57+
if (ColumnOptions.Store.Contains(StandardColumn.MessageTemplate)) ExcludedColumnNames.Add(ColumnOptions.MessageTemplate.ColumnName ?? "MessageTemplate");
58+
if (ColumnOptions.Store.Contains(StandardColumn.Level)) ExcludedColumnNames.Add(ColumnOptions.Level.ColumnName ?? "Level");
59+
if (ColumnOptions.Store.Contains(StandardColumn.TimeStamp)) ExcludedColumnNames.Add(ColumnOptions.TimeStamp.ColumnName ?? "TimeStamp");
60+
if (ColumnOptions.Store.Contains(StandardColumn.Exception)) ExcludedColumnNames.Add(ColumnOptions.Exception.ColumnName ?? "Exception");
61+
if (ColumnOptions.Store.Contains(StandardColumn.Properties)) ExcludedColumnNames.Add(ColumnOptions.Properties.ColumnName ?? "Properties");
62+
if (ColumnOptions.Store.Contains(StandardColumn.LogEvent)) ExcludedColumnNames.Add(ColumnOptions.LogEvent.ColumnName ?? "LogEvent");
5863

5964
if (ColumnOptions.AdditionalDataColumns != null)
6065
AdditionalDataColumnNames = new HashSet<string>(ColumnOptions.AdditionalDataColumns.Select(c => c.ColumnName), StringComparer.OrdinalIgnoreCase);
@@ -114,7 +119,7 @@ private KeyValuePair<string, object> GetStandardColumnNameAndValue(StandardColum
114119
case StandardColumn.Level:
115120
return new KeyValuePair<string, object>(ColumnOptions.Level.ColumnName ?? "Level", ColumnOptions.Level.StoreAsEnum ? (object)logEvent.Level : logEvent.Level.ToString());
116121
case StandardColumn.TimeStamp:
117-
return new KeyValuePair<string, object>(ColumnOptions.TimeStamp.ColumnName ?? "TimeStamp", ColumnOptions.TimeStamp.ConvertToUtc ? logEvent.Timestamp.ToUniversalTime() : logEvent.Timestamp.DateTime);
122+
return new KeyValuePair<string, object>(ColumnOptions.TimeStamp.ColumnName ?? "TimeStamp", ColumnOptions.TimeStamp.ConvertToUtc ? logEvent.Timestamp.ToUniversalTime().DateTime : logEvent.Timestamp.DateTime);
118123
case StandardColumn.Exception:
119124
return new KeyValuePair<string, object>(ColumnOptions.Exception.ColumnName ?? "Exception", logEvent.Exception != null ? logEvent.Exception.ToString() : null);
120125
case StandardColumn.Properties:

test/Serilog.Sinks.MSSqlServer.Tests/Serilog.Sinks.MSSqlServer.Tests.csproj

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,10 @@
5656
<PackageReference Include="System.Text.Encoding.Extensions" Version="4.3.0" />
5757
<PackageReference Include="xunit" Version="2.3.0" />
5858
<PackageReference Include="xunit.core" Version="2.3.0" />
59-
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.0" NoWarn="NU1701" />
59+
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.0" NoWarn="NU1701">
60+
<PrivateAssets>all</PrivateAssets>
61+
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
62+
</PackageReference>
6063
<Compile Include="Configuration\Microsoft.Extensions.Configuration\**\*.cs" />
6164
</ItemGroup>
6265

0 commit comments

Comments
 (0)