Skip to content

Commit 50651b3

Browse files
committed
Added carriage return and linefeed characters to disallowed row key chars
Fixes #10
1 parent cebf775 commit 50651b3

File tree

2 files changed

+48
-2
lines changed

2 files changed

+48
-2
lines changed

src/Serilog.Sinks.AzureTableStorage/Sinks/AzureTableStorageWithProperties/AzureTableStorageEntityFactory.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ namespace Serilog.Sinks.AzureTableStorage
2828
public static class AzureTableStorageEntityFactory
2929
{
3030
// Valid RowKey name characters
31-
static readonly Regex _rowKeyNotAllowedMatch = new Regex(@"(\\|/|#|\?)");
31+
static readonly Regex _rowKeyNotAllowedMatch = new Regex(@"(\\|/|#|\n|\r|\?)");
3232

3333
// Azure tables support a maximum of 255 properties. PartitionKey, RowKey and Timestamp
3434
// bring the maximum to 252.

test/Serilog.Sinks.AzureTableStorageWithProperties.Tests/AzureTableStorageWithPropertiesSinkTests.cs

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,30 @@ public void WhenALoggerWritesToTheSinkItIsRetrievableFromTheTableWithProperties(
7575
}
7676

7777
[Fact]
78-
public void WhenALoggerWritesToTheSinkWithANewlineInTheTemplateItIsRetrievable()
78+
public void WhenALoggerWritesToTheSinkWithAWindowsNewlineInTheTemplateItIsRetrievable()
79+
{
80+
// Prompted from https://github.com/serilog/serilog-sinks-azuretablestorage/issues/10
81+
var storageAccount = CloudStorageAccount.DevelopmentStorageAccount;
82+
var tableClient = storageAccount.CreateCloudTableClient();
83+
var table = tableClient.GetTableReference("LogEventEntity");
84+
85+
table.DeleteIfExists();
86+
87+
var logger = new LoggerConfiguration()
88+
.WriteTo.AzureTableStorageWithProperties(storageAccount)
89+
.CreateLogger();
90+
91+
const string messageTemplate = "Line 1\r\nLine2";
92+
93+
logger.Information(messageTemplate);
94+
95+
var result = table.ExecuteQuery(new TableQuery().Take(1)).FirstOrDefault();
96+
97+
Assert.NotNull(result);
98+
}
99+
100+
[Fact]
101+
public void WhenALoggerWritesToTheSinkWithALineFeedInTheTemplateItIsRetrievable()
79102
{
80103
// Prompted from https://github.com/serilog/serilog-sinks-azuretablestorage/issues/10
81104
var storageAccount = CloudStorageAccount.DevelopmentStorageAccount;
@@ -97,6 +120,29 @@ public void WhenALoggerWritesToTheSinkWithANewlineInTheTemplateItIsRetrievable()
97120
Assert.NotNull(result);
98121
}
99122

123+
[Fact]
124+
public void WhenALoggerWritesToTheSinkWithACarriageReturnInTheTemplateItIsRetrievable()
125+
{
126+
// Prompted from https://github.com/serilog/serilog-sinks-azuretablestorage/issues/10
127+
var storageAccount = CloudStorageAccount.DevelopmentStorageAccount;
128+
var tableClient = storageAccount.CreateCloudTableClient();
129+
var table = tableClient.GetTableReference("LogEventEntity");
130+
131+
table.DeleteIfExists();
132+
133+
var logger = new LoggerConfiguration()
134+
.WriteTo.AzureTableStorageWithProperties(storageAccount)
135+
.CreateLogger();
136+
137+
const string messageTemplate = "Line 1\rLine2";
138+
139+
logger.Information(messageTemplate);
140+
141+
var result = table.ExecuteQuery(new TableQuery().Take(1)).FirstOrDefault();
142+
143+
Assert.NotNull(result);
144+
}
145+
100146
[Fact]
101147
public void WhenALoggerWritesToTheSinkItStoresTheCorrectTypesForScalar()
102148
{

0 commit comments

Comments
 (0)