-
Notifications
You must be signed in to change notification settings - Fork 101
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #192 from serilog/dev
3.1.0 Release
- Loading branch information
Showing
18 changed files
with
378 additions
and
46 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
{ | ||
"sdk": { | ||
"version": "2.2.103" | ||
"allowPrerelease": false, | ||
"version": "3.1.100", | ||
"rollForward": "latestFeature" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
src/Serilog.Extensions.Logging/Extensions/Logging/CachingMessageTemplateParser.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// Copyright (c) Serilog Contributors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
|
||
using System; | ||
using Serilog.Events; | ||
using Serilog.Parsing; | ||
using System.Collections; | ||
|
||
namespace Serilog.Extensions.Logging | ||
{ | ||
class CachingMessageTemplateParser | ||
{ | ||
readonly MessageTemplateParser _innerParser = new MessageTemplateParser(); | ||
|
||
readonly object _templatesLock = new object(); | ||
readonly Hashtable _templates = new Hashtable(); | ||
|
||
const int MaxCacheItems = 1000; | ||
const int MaxCachedTemplateLength = 1024; | ||
|
||
public MessageTemplate Parse(string messageTemplate) | ||
{ | ||
if (messageTemplate == null) throw new ArgumentNullException(nameof(messageTemplate)); | ||
|
||
if (messageTemplate.Length > MaxCachedTemplateLength) | ||
return _innerParser.Parse(messageTemplate); | ||
|
||
// ReSharper disable once InconsistentlySynchronizedField | ||
// ignored warning because this is by design | ||
var result = (MessageTemplate)_templates[messageTemplate]; | ||
if (result != null) | ||
return result; | ||
|
||
result = _innerParser.Parse(messageTemplate); | ||
|
||
lock (_templatesLock) | ||
{ | ||
// Exceeding MaxCacheItems is *not* the sunny day scenario; all we're doing here is preventing out-of-memory | ||
// conditions when the library is used incorrectly. Correct use (templates, rather than | ||
// direct message strings) should barely, if ever, overflow this cache. | ||
|
||
// Changing workloads through the lifecycle of an app instance mean we can gain some ground by | ||
// potentially dropping templates generated only in startup, or only during specific infrequent | ||
// activities. | ||
|
||
if (_templates.Count == MaxCacheItems) | ||
_templates.Clear(); | ||
|
||
_templates[messageTemplate] = result; | ||
} | ||
|
||
return result; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.