Skip to content

Commit c9c6bb0

Browse files
authored
Merge pull request #114 from serilog/dev
5.1.1 Release
2 parents 5bfc443 + 560c009 commit c9c6bb0

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ var log = new LoggerConfiguration()
2828
If you are configuring Serilog with the `ReadFrom.AppSettings()` XML configuration support, you can use:
2929

3030
```xml
31-
<add key="serilog:using:MSSqlSever" value="Serilog.Sinks.MSSqlServer" />
31+
<add key="serilog:using:MSSqlServer" value="Serilog.Sinks.MSSqlServer" />
3232
<add key="serilog:write-to:MSSqlServer.connectionString" value="Server=..."/>
3333
<add key="serilog:write-to:MSSqlServer.tableName" value="Logs"/>
3434
<add key="serilog:write-to:MSSqlServer.autoCreateSqlTable" value="true"/>

src/Serilog.Sinks.MSSqlServer/Serilog.Sinks.MSSqlServer.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<Description>A Serilog sink that writes events to Microsoft SQL Server</Description>
5-
<VersionPrefix>5.1.0</VersionPrefix>
5+
<VersionPrefix>5.1.1</VersionPrefix>
66
<Authors>Michiel van Oudheusden;Serilog Contributors</Authors>
77
<TargetFrameworks>netstandard2.0;net45;net452</TargetFrameworks>
88
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>

src/Serilog.Sinks.MSSqlServer/Sinks/MSSqlServer/XmlPropertyFormatter.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2015 Serilog Contributors
1+
// Copyright 2015 Serilog Contributors
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -28,6 +28,14 @@ namespace Serilog.Sinks.MSSqlServer
2828
/// </summary>
2929
public static class XmlPropertyFormatter
3030
{
31+
32+
/// <summary>
33+
/// Regex to trasnform any non-xml char into ?, acoiding any exceptions on inserting the xml properties into the database
34+
/// </summary>
35+
private static Regex _invalidXMLChars = new Regex(
36+
@"(?<![\uD800-\uDBFF])[\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|[\x00-\x08\x0B\x0C\x0E-\x1F\x7F-\x9F\uFEFF\uFFFE\uFFFF]",
37+
RegexOptions.Compiled);
38+
3139
/// <summary>
3240
/// Simplify the object so as to make handling the serialized
3341
/// representation easier.
@@ -204,7 +212,7 @@ static string SimplifyScalar(object value)
204212
{
205213
if (value == null) return null;
206214

207-
return new XText(value.ToString()).ToString();
215+
return new XText(_invalidXMLChars.Replace(value.ToString(), m => "\\u" + ((ushort)m.Value[0]).ToString("x4"))).ToString();
208216
}
209217
}
210-
}
218+
}

0 commit comments

Comments
 (0)