Skip to content

Commit 3be2e22

Browse files
authored
Merge pull request #313 from ckadluba/issue-312-conversion-fail
Fixed issue 312
2 parents d43d627 + 36a8782 commit 3be2e22

File tree

3 files changed

+49
-18
lines changed

3 files changed

+49
-18
lines changed

appveyor.yml

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,23 @@ configuration: Release
55
install:
66
- ps: mkdir -Force ".\build\" | Out-Null
77
build_script:
8-
- ps: ./Build.ps1
8+
- ps: ./Build.ps1
99
test: off
1010
artifacts:
11-
- path: artifacts/Serilog.*.nupkg
12-
- path: artifacts/Serilog.*.snupkg
11+
- path: artifacts/Serilog.*.nupkg
12+
- path: artifacts/Serilog.*.snupkg
1313
deploy:
14-
- provider: NuGet
15-
api_key:
16-
secure: K3/810hkTO6rd2AEHVkUQAadjGmDREus9k96QHu6hxrA1/wRTuAJemHMKtVVgIvf
17-
on:
18-
branch: /^(master|dev)$/
19-
- provider: GitHub
20-
auth_token:
21-
secure: p4LpVhBKxGS5WqucHxFQ5c7C8cP74kbNB0Z8k9Oxx/PMaDQ1+ibmoexNqVU5ZlmX
22-
artifacts:
23-
/Serilog.*\.nupkg/
24-
/Serilog.*\.snupkg/
25-
tag: v$(appveyor_build_version)
26-
on:
27-
branch: master
14+
- provider: NuGet
15+
api_key:
16+
secure: K3/810hkTO6rd2AEHVkUQAadjGmDREus9k96QHu6hxrA1/wRTuAJemHMKtVVgIvf
17+
on:
18+
branch: /^(master|dev)$/
19+
- provider: GitHub
20+
auth_token:
21+
secure: p4LpVhBKxGS5WqucHxFQ5c7C8cP74kbNB0Z8k9Oxx/PMaDQ1+ibmoexNqVU5ZlmX
22+
artifacts:
23+
/Serilog.*\.nupkg/
24+
/Serilog.*\.snupkg/
25+
tag: v$(appveyor_build_version)
26+
on:
27+
branch: master

src/Serilog.Sinks.MSSqlServer/Sinks/MSSqlServer/Output/PropertiesColumnDataGenerator.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.ComponentModel;
34
using System.Globalization;
45
using System.Linq;
56
using Serilog.Events;
@@ -49,6 +50,12 @@ public IEnumerable<KeyValuePair<string, object>> ConvertPropertiesToColumn(IRead
4950
continue;
5051
}
5152

53+
if (columnType.IsAssignableFrom(scalarValue.Value.GetType()))
54+
{
55+
yield return new KeyValuePair<string, object>(columnName, scalarValue.Value);
56+
continue;
57+
}
58+
5259
if (TryChangeType(scalarValue.Value, columnType, out var conversion))
5360
{
5461
yield return new KeyValuePair<string, object>(columnName, conversion);
@@ -65,7 +72,7 @@ private static bool TryChangeType(object obj, Type type, out object conversion)
6572
conversion = null;
6673
try
6774
{
68-
conversion = Convert.ChangeType(obj, type, CultureInfo.InvariantCulture);
75+
conversion = TypeDescriptor.GetConverter(type).ConvertFrom(obj);
6976
return true;
7077
}
7178
catch

test/Serilog.Sinks.MSSqlServer.Tests/Sinks/MSSqlServer/Output/PropertiesColumnDataGeneratorTests.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,30 @@ public void ConvertPropertiesToColumnConvertsValueTypeToStringIfConversionToColu
137137
Assert.Equal("1", result[0].Value);
138138
}
139139

140+
[Fact]
141+
public void ConvertPropertiesToColumnConvertsUniqueIdentifier()
142+
{
143+
// Arrange
144+
const string propertyKey = "AdditionalProperty1";
145+
const string propertyValue = "7526f485-ec2d-4ec8-bd73-12a7d1c49a5d";
146+
var properties = new ReadOnlyDictionary<string, LogEventPropertyValue>(
147+
new Dictionary<string, LogEventPropertyValue>
148+
{
149+
{ propertyKey, new ScalarValue(propertyValue) }
150+
});
151+
_columnOptions.AdditionalColumns.Add(new SqlColumn(propertyKey, SqlDbType.UniqueIdentifier));
152+
CreateSut();
153+
154+
// Act
155+
var result = _sut.ConvertPropertiesToColumn(properties).ToArray();
156+
157+
// Assert
158+
var expectedResult = Guid.Parse(propertyValue);
159+
Assert.Equal(propertyKey, result[0].Key);
160+
Assert.IsType<Guid>(result[0].Value);
161+
Assert.Equal(expectedResult, result[0].Value);
162+
}
163+
140164
private void CreateSut()
141165
{
142166
_sut = new PropertiesColumnDataGenerator(_columnOptions);

0 commit comments

Comments
 (0)