File tree Expand file tree Collapse file tree 3 files changed +13
-5
lines changed
src/Serilog.Sinks.MSSqlServer Expand file tree Collapse file tree 3 files changed +13
-5
lines changed Original file line number Diff line number Diff line change @@ -28,7 +28,7 @@ var log = new LoggerConfiguration()
28
28
If you are configuring Serilog with the ` ReadFrom.AppSettings() ` XML configuration support, you can use:
29
29
30
30
``` xml
31
- <add key =" serilog:using:MSSqlSever " value =" Serilog.Sinks.MSSqlServer" />
31
+ <add key =" serilog:using:MSSqlServer " value =" Serilog.Sinks.MSSqlServer" />
32
32
<add key =" serilog:write-to:MSSqlServer.connectionString" value =" Server=..." />
33
33
<add key =" serilog:write-to:MSSqlServer.tableName" value =" Logs" />
34
34
<add key =" serilog:write-to:MSSqlServer.autoCreateSqlTable" value =" true" />
Original file line number Diff line number Diff line change 2
2
3
3
<PropertyGroup >
4
4
<Description >A Serilog sink that writes events to Microsoft SQL Server</Description >
5
- <VersionPrefix >5.1.0 </VersionPrefix >
5
+ <VersionPrefix >5.1.1 </VersionPrefix >
6
6
<Authors >Michiel van Oudheusden;Serilog Contributors</Authors >
7
7
<TargetFrameworks >netstandard2.0;net45;net452</TargetFrameworks >
8
8
<TreatWarningsAsErrors >true</TreatWarningsAsErrors >
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