diff --git a/README.md b/README.md
index 123e0d63..9c0916e6 100644
--- a/README.md
+++ b/README.md
@@ -28,7 +28,7 @@ var log = new LoggerConfiguration()
If you are configuring Serilog with the `ReadFrom.AppSettings()` XML configuration support, you can use:
```xml
-
+
diff --git a/src/Serilog.Sinks.MSSqlServer/Serilog.Sinks.MSSqlServer.csproj b/src/Serilog.Sinks.MSSqlServer/Serilog.Sinks.MSSqlServer.csproj
index b49a1af8..8553e7af 100644
--- a/src/Serilog.Sinks.MSSqlServer/Serilog.Sinks.MSSqlServer.csproj
+++ b/src/Serilog.Sinks.MSSqlServer/Serilog.Sinks.MSSqlServer.csproj
@@ -2,7 +2,7 @@
A Serilog sink that writes events to Microsoft SQL Server
- 5.1.0
+ 5.1.1
Michiel van Oudheusden;Serilog Contributors
netstandard2.0;net45;net452
true
diff --git a/src/Serilog.Sinks.MSSqlServer/Sinks/MSSqlServer/XmlPropertyFormatter.cs b/src/Serilog.Sinks.MSSqlServer/Sinks/MSSqlServer/XmlPropertyFormatter.cs
index 805f7d34..c13ce0a8 100644
--- a/src/Serilog.Sinks.MSSqlServer/Sinks/MSSqlServer/XmlPropertyFormatter.cs
+++ b/src/Serilog.Sinks.MSSqlServer/Sinks/MSSqlServer/XmlPropertyFormatter.cs
@@ -1,4 +1,4 @@
-// Copyright 2015 Serilog Contributors
+// Copyright 2015 Serilog Contributors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@@ -28,6 +28,14 @@ namespace Serilog.Sinks.MSSqlServer
///
public static class XmlPropertyFormatter
{
+
+ ///
+ /// Regex to trasnform any non-xml char into ?, acoiding any exceptions on inserting the xml properties into the database
+ ///
+ private static Regex _invalidXMLChars = new Regex(
+ @"(?
/// Simplify the object so as to make handling the serialized
/// representation easier.
@@ -204,7 +212,7 @@ static string SimplifyScalar(object value)
{
if (value == null) return null;
- return new XText(value.ToString()).ToString();
+ return new XText(_invalidXMLChars.Replace(value.ToString(), m => "\\u" + ((ushort)m.Value[0]).ToString("x4"))).ToString();
}
}
-}
\ No newline at end of file
+}