-
Notifications
You must be signed in to change notification settings - Fork 17
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 #20 from serilog/renderings-property
Test templates by comparing output with existing formatters
- Loading branch information
Showing
12 changed files
with
377 additions
and
35 deletions.
There are no files selected for viewing
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
55 changes: 55 additions & 0 deletions
55
src/Serilog.Expressions/Expressions/Compilation/Linq/EventIdHash.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,55 @@ | ||
// Copyright © 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; | ||
|
||
// ReSharper disable ForCanBeConvertedToForeach | ||
|
||
namespace Serilog.Expressions.Compilation.Linq | ||
{ | ||
/// <summary> | ||
/// Hash functions for message templates. See <see cref="Compute"/>. | ||
/// </summary> | ||
public static class EventIdHash | ||
{ | ||
/// <summary> | ||
/// Compute a 32-bit hash of the provided <paramref name="messageTemplate"/>. The | ||
/// resulting hash value can be uses as an event id in lieu of transmitting the | ||
/// full template string. | ||
/// </summary> | ||
/// <param name="messageTemplate">A message template.</param> | ||
/// <returns>A 32-bit hash of the template.</returns> | ||
[CLSCompliant(false)] | ||
public static uint Compute(string messageTemplate) | ||
{ | ||
if (messageTemplate == null) throw new ArgumentNullException(nameof(messageTemplate)); | ||
|
||
// Jenkins one-at-a-time https://en.wikipedia.org/wiki/Jenkins_hash_function | ||
unchecked | ||
{ | ||
uint hash = 0; | ||
for (var i = 0; i < messageTemplate.Length; ++i) | ||
{ | ||
hash += messageTemplate[i]; | ||
hash += hash << 10; | ||
hash ^= hash >> 6; | ||
} | ||
hash += hash << 3; | ||
hash ^= hash >> 11; | ||
hash += hash << 15; | ||
return hash; | ||
} | ||
} | ||
} | ||
} |
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
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.