Skip to content

Commit

Permalink
Merge pull request #114 from serilog/dev
Browse files Browse the repository at this point in the history
5.1.1 Release
  • Loading branch information
nblumhardt authored Mar 12, 2018
2 parents 5bfc443 + 560c009 commit c9c6bb0
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ var log = new LoggerConfiguration()
If you are configuring Serilog with the `ReadFrom.AppSettings()` XML configuration support, you can use:

```xml
<add key="serilog:using:MSSqlSever" value="Serilog.Sinks.MSSqlServer" />
<add key="serilog:using:MSSqlServer" value="Serilog.Sinks.MSSqlServer" />
<add key="serilog:write-to:MSSqlServer.connectionString" value="Server=..."/>
<add key="serilog:write-to:MSSqlServer.tableName" value="Logs"/>
<add key="serilog:write-to:MSSqlServer.autoCreateSqlTable" value="true"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<Description>A Serilog sink that writes events to Microsoft SQL Server</Description>
<VersionPrefix>5.1.0</VersionPrefix>
<VersionPrefix>5.1.1</VersionPrefix>
<Authors>Michiel van Oudheusden;Serilog Contributors</Authors>
<TargetFrameworks>netstandard2.0;net45;net452</TargetFrameworks>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -28,6 +28,14 @@ namespace Serilog.Sinks.MSSqlServer
/// </summary>
public static class XmlPropertyFormatter
{

/// <summary>
/// Regex to trasnform any non-xml char into ?, acoiding any exceptions on inserting the xml properties into the database
/// </summary>
private static Regex _invalidXMLChars = new Regex(
@"(?<![\uD800-\uDBFF])[\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|[\x00-\x08\x0B\x0C\x0E-\x1F\x7F-\x9F\uFEFF\uFFFE\uFFFF]",
RegexOptions.Compiled);

/// <summary>
/// Simplify the object so as to make handling the serialized
/// representation easier.
Expand Down Expand Up @@ -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();
}
}
}
}

0 comments on commit c9c6bb0

Please sign in to comment.