Skip to content

Commit b4ba091

Browse files
authored
Merge pull request #46 from serilog/dev
4.1.1 Release
2 parents 50ac426 + 5f44fe6 commit b4ba091

File tree

8 files changed

+108
-23
lines changed

8 files changed

+108
-23
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ DataTable CreateDataTable()
174174
eventsTable.Columns.Add(new DataColumn
175175
{
176176
DataType = _columnOptions.Level.StoreAsEnum ? typeof(byte) : typeof(string),
177-
MaxLength = _columnOptions.Level.StoreAsEnum ? 0 : 128,
177+
MaxLength = _columnOptions.Level.StoreAsEnum ? -1 : 128,
178178
ColumnName = _columnOptions.Level.ColumnName ?? StandardColumn.Level.ToString()
179179
});
180180
break;

src/Serilog.Sinks.MSSqlServer/project.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": "4.1.0-*",
2+
"version": "4.1.1-*",
33
"description": "A Serilog sink that writes events to Microsoft SQL Server",
44
"authors": [
55
"Michiel van Oudheusden",

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,15 @@
33
using System.Data.SqlClient;
44
using System.IO;
55
using System.Linq;
6-
using System.Threading;
7-
using System.Threading.Tasks;
86
using Dapper;
97
using Xunit;
108
using FluentAssertions;
119
using Serilog.Events;
1210

1311
namespace Serilog.Sinks.MSSqlServer.Tests
1412
{
15-
public class CustomStandardColumnNames : IClassFixture<DatabaseFixture>
13+
[Collection("LogTest")]
14+
public class CustomStandardColumnNames
1615
{
1716
[Fact]
1817
public void CustomIdColumn()
@@ -131,15 +130,13 @@ public void WriteEventToDefaultStandardColumns()
131130
columnOptions: new ColumnOptions())
132131
.CreateLogger();
133132

134-
var file = File.CreateText("Self.log");
133+
var file = File.CreateText("StandardColumns.Self.log");
135134
Serilog.Debugging.SelfLog.Enable(TextWriter.Synchronized(file));
136135

137136
// act
138137
const string loggingInformationMessage = "Logging Information message";
139138
Log.Information(loggingInformationMessage);
140139

141-
//Thread.Sleep(50);
142-
143140
Log.CloseAndFlush();
144141

145142
// assert

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Data.SqlClient;
33
using System.Linq;
44
using Dapper;
5+
using Xunit;
56

67
namespace Serilog.Sinks.MSSqlServer.Tests
78
{
@@ -70,4 +71,7 @@ private static void CreateDatabase()
7071
}
7172
}
7273
}
74+
75+
[CollectionDefinition("LogTest")]
76+
public class PatientSecureFixtureCollection : ICollectionFixture<DatabaseFixture> { }
7377
}

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

Lines changed: 0 additions & 12 deletions
This file was deleted.
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
using System;
2+
using System.Data.SqlClient;
3+
using System.Diagnostics;
4+
using System.IO;
5+
using Dapper;
6+
using FluentAssertions;
7+
using Serilog.Events;
8+
using Xunit;
9+
10+
namespace Serilog.Sinks.MSSqlServer.Tests
11+
{
12+
[Collection("LogTest")]
13+
public class LevelAsEnum
14+
{
15+
[Fact]
16+
public void CanStoreLevelAsEnum()
17+
{
18+
// arrange
19+
const string tableName = "LogEventsLevelAsEnum";
20+
var loggerConfiguration = new LoggerConfiguration();
21+
Log.Logger = loggerConfiguration.WriteTo.MSSqlServer(
22+
connectionString: DatabaseFixture.LogEventsConnectionString,
23+
tableName: tableName,
24+
autoCreateSqlTable: true,
25+
batchPostingLimit: 1,
26+
period: TimeSpan.FromSeconds(10),
27+
columnOptions: new ColumnOptions { Level = { StoreAsEnum = true } })
28+
.CreateLogger();
29+
30+
var file = File.CreateText("LevelAsEnum.True.Enum.Self.log");
31+
Serilog.Debugging.SelfLog.Enable(TextWriter.Synchronized(file));
32+
33+
// act
34+
const string loggingInformationMessage = "Logging Information message";
35+
Log.Information(loggingInformationMessage);
36+
Log.CloseAndFlush();
37+
38+
// assert
39+
using (var conn = new SqlConnection(DatabaseFixture.LogEventsConnectionString))
40+
{
41+
var logEvents = conn.Query<EnumLevelStandardLogColumns>($"SELECT Message, Level FROM {tableName}");
42+
43+
logEvents.Should().Contain(e => e.Message.Contains(loggingInformationMessage) && e.Level == 2);
44+
}
45+
}
46+
47+
[Fact]
48+
public void CanStoreLevelAsString()
49+
{
50+
// arrange
51+
const string tableName = "LogEventsLevelAsString";
52+
var loggerConfiguration = new LoggerConfiguration();
53+
Log.Logger = loggerConfiguration.WriteTo.MSSqlServer(
54+
connectionString: DatabaseFixture.LogEventsConnectionString,
55+
tableName: tableName,
56+
autoCreateSqlTable: true,
57+
batchPostingLimit: 1,
58+
period: TimeSpan.FromSeconds(10),
59+
columnOptions: new ColumnOptions { Level = { StoreAsEnum = false } })
60+
.CreateLogger();
61+
62+
var file = File.CreateText("LevelAsEnum.False.Self.log");
63+
Serilog.Debugging.SelfLog.Enable(TextWriter.Synchronized(file));
64+
65+
// act
66+
const string loggingInformationMessage = "Logging Information message";
67+
Log.Information(loggingInformationMessage);
68+
Log.CloseAndFlush();
69+
70+
// assert
71+
using (var conn = new SqlConnection(DatabaseFixture.LogEventsConnectionString))
72+
{
73+
var logEvents = conn.Query<StringLevelStandardLogColumns>($"SELECT Message, Level FROM {tableName}");
74+
75+
logEvents.Should().Contain(e => e.Message.Contains(loggingInformationMessage) && e.Level == LogEventLevel.Information.ToString());
76+
}
77+
}
78+
}
79+
80+
public class EnumLevelStandardLogColumns
81+
{
82+
public string Message { get; set; }
83+
84+
public byte Level { get; set; }
85+
}
86+
87+
public class StringLevelStandardLogColumns
88+
{
89+
public string Message { get; set; }
90+
91+
public string Level { get; set; }
92+
}
93+
}

test/Serilog.Sinks.MSSqlServer.Tests/Serilog.Sinks.MSSqlServer.Tests.xproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,8 @@
1414
<PropertyGroup>
1515
<SchemaVersion>2.0</SchemaVersion>
1616
</PropertyGroup>
17+
<ItemGroup>
18+
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
19+
</ItemGroup>
1720
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.targets" Condition="'$(VSToolsPath)' != ''" />
1821
</Project>

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@
434434
"lib/net45/xunit.runner.utility.desktop.dll": {}
435435
}
436436
},
437-
"Serilog.Sinks.MSSqlServer/4.1.0": {
437+
"Serilog.Sinks.MSSqlServer/4.1.1": {
438438
"type": "project",
439439
"framework": ".NETFramework,Version=v4.5",
440440
"dependencies": {
@@ -852,7 +852,7 @@
852852
"lib/net45/xunit.runner.utility.desktop.dll": {}
853853
}
854854
},
855-
"Serilog.Sinks.MSSqlServer/4.1.0": {
855+
"Serilog.Sinks.MSSqlServer/4.1.1": {
856856
"type": "project",
857857
"framework": ".NETFramework,Version=v4.5",
858858
"dependencies": {
@@ -1622,7 +1622,7 @@
16221622
"xunit.runner.utility.nuspec"
16231623
]
16241624
},
1625-
"Serilog.Sinks.MSSqlServer/4.1.0": {
1625+
"Serilog.Sinks.MSSqlServer/4.1.1": {
16261626
"type": "project",
16271627
"path": "../../src/Serilog.Sinks.MSSqlServer/project.json",
16281628
"msbuildProject": "../../src/Serilog.Sinks.MSSqlServer/Serilog.Sinks.MSSqlServer.xproj"

0 commit comments

Comments
 (0)