Skip to content

Commit fdc3aaa

Browse files
author
Colin Young
committed
Verify default standard event column names are used
1 parent bce1057 commit fdc3aaa

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

test/Serilog.Sinks.MSSqlServer.Tests/CustomStandardColumnNames.cs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Data.SqlClient;
4+
using System.IO;
45
using System.Linq;
6+
using System.Threading;
7+
using System.Threading.Tasks;
58
using Dapper;
69
using Xunit;
710
using FluentAssertions;
11+
using Serilog.Events;
812

913
namespace Serilog.Sinks.MSSqlServer.Tests
1014
{
@@ -111,5 +115,46 @@ public void TableCreatedWithDefaultNames()
111115
}
112116
}
113117
}
118+
119+
[Fact]
120+
public void WriteEventToDefaultStandardColumns()
121+
{
122+
// arrange
123+
var loggerConfiguration = new LoggerConfiguration();
124+
Log.Logger = loggerConfiguration.WriteTo.MSSqlServer(
125+
connectionString: DatabaseFixture.LogEventsConnectionString,
126+
tableName: DatabaseFixture.LogTableName,
127+
autoCreateSqlTable: true,
128+
batchPostingLimit: 1,
129+
period: TimeSpan.FromSeconds(10),
130+
columnOptions: new ColumnOptions())
131+
.CreateLogger();
132+
133+
var file = File.CreateText("Self.log");
134+
Serilog.Debugging.SelfLog.Enable(TextWriter.Synchronized(file));
135+
136+
// act
137+
const string loggingInformationMessage = "Logging Information message";
138+
Log.Information(loggingInformationMessage);
139+
140+
//Thread.Sleep(50);
141+
142+
Log.CloseAndFlush();
143+
144+
// assert
145+
using (var conn = new SqlConnection(DatabaseFixture.LogEventsConnectionString))
146+
{
147+
var logEvents = conn.Query<DefaultStandardLogColumns>($"SELECT Message, Level FROM {DatabaseFixture.LogTableName}");
148+
149+
logEvents.Should().Contain(e => e.Message.Contains(loggingInformationMessage));
150+
}
151+
}
152+
}
153+
154+
public class DefaultStandardLogColumns
155+
{
156+
public string Message { get; set; }
157+
158+
public LogEventLevel Level { get; set; }
114159
}
115160
}

test/Serilog.Sinks.MSSqlServer.Tests/project.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
"FluentAssertions": "4.13.0",
99
"Dapper.StrongName": "1.50.2"
1010
},
11-
1211
"buildOptions": {
1312
"keyFile": "../../assets/Serilog.snk"
1413
},

0 commit comments

Comments
 (0)