File tree Expand file tree Collapse file tree 1 file changed +11
-3
lines changed
src/Serilog.Sinks.MSSqlServer/Sinks/MSSqlServer Expand file tree Collapse file tree 1 file changed +11
-3
lines changed Original file line number Diff line number Diff line change 1
- // Copyright 2015 Serilog Contributors
1
+ // Copyright 2015 Serilog Contributors
2
2
//
3
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
4
// you may not use this file except in compliance with the License.
@@ -28,6 +28,14 @@ namespace Serilog.Sinks.MSSqlServer
28
28
/// </summary>
29
29
public static class XmlPropertyFormatter
30
30
{
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
+
31
39
/// <summary>
32
40
/// Simplify the object so as to make handling the serialized
33
41
/// representation easier.
@@ -204,7 +212,7 @@ static string SimplifyScalar(object value)
204
212
{
205
213
if ( value == null ) return null ;
206
214
207
- return new XText ( value . ToString ( ) ) . ToString ( ) ;
215
+ return new XText ( _invalidXMLChars . Replace ( value . ToString ( ) , m => " \\ u" + ( ( ushort ) m . Value [ 0 ] ) . ToString ( "x4" ) ) ) . ToString ( ) ;
208
216
}
209
217
}
210
- }
218
+ }
You can’t perform that action at this time.
0 commit comments