Skip to content

3.5.0 Release #101

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Sep 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ User-defined functions are supplied through an instance of `NameResolver`:

```csharp
var myFunctions = new StaticMemberNameResolver(typeof(MyFunctions));
var expr = SerilogExpression.Compile("IsHello(User.Name)", nameResolver: customSerilogFunctions);
var expr = SerilogExpression.Compile("IsHello(User.Name)", nameResolver: myFunctions);
// Filter events based on whether `User.Name` is `'Hello'` :-)
```

Expand Down
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ artifacts:
deploy:
- provider: NuGet
api_key:
secure: xIn2Dlahvk1QLaFAazCkjSc83UC1Uv5jeMeyA2NDDiLeHZwFqMm5da6nHEzm6ks5
secure: AcMGMnsJdQe1+SQwf+9VpRqcKNw93zr96OlxAEmPob52vqxDNH844SmdYidGX0cL
skip_symbols: true
on:
branch: /^(main|dev)$/
Expand Down
4 changes: 2 additions & 2 deletions src/Serilog.Expressions/Serilog.Expressions.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<Description>An embeddable mini-language for filtering, enriching, and formatting Serilog
events, ideal for use with JSON or XML configuration.</Description>
<VersionPrefix>3.4.1</VersionPrefix>
<VersionPrefix>3.5.0</VersionPrefix>
<Authors>Serilog Contributors</Authors>
<TargetFrameworks>netstandard2.0;netstandard2.1;net5.0</TargetFrameworks>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
Expand All @@ -17,7 +17,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Serilog" Version="2.10.0" />
<PackageReference Include="Serilog" Version="2.12.0" />
<PackageReference Include="Nullable" Version="1.3.0" PrivateAssets="All" />
</ItemGroup>

Expand Down
37 changes: 20 additions & 17 deletions src/Serilog.Expressions/Templates/Compilation/CompiledRepetition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,22 @@ class CompiledRepetition : CompiledTemplate
{
readonly Evaluatable _enumerable;
readonly string? _keyOrElementName;
readonly string? _valueName;
readonly string? _valueOrIndexName;
readonly CompiledTemplate _body;
readonly CompiledTemplate? _delimiter;
readonly CompiledTemplate? _alternative;

public CompiledRepetition(
Evaluatable enumerable,
string? keyOrElementName,
string? valueName,
string? valueOrIndexName,
CompiledTemplate body,
CompiledTemplate? delimiter,
CompiledTemplate? alternative)
{
_enumerable = enumerable;
_keyOrElementName = keyOrElementName;
_valueName = valueName;
_valueOrIndexName = valueOrIndexName;
_body = body;
_delimiter = delimiter;
_alternative = alternative;
Expand All @@ -52,29 +52,32 @@ public override void Evaluate(EvaluationContext ctx, TextWriter output)
return;
}

if (enumerable is SequenceValue sv)
if (enumerable is SequenceValue sequence)
{
if (sv.Elements.Count == 0)
if (sequence.Elements.Count == 0)
{
_alternative?.Evaluate(ctx, output);
return;
}

var first = true;
foreach (var element in sv.Elements)
for (var i = 0; i < sequence.Elements.Count; ++i)
{
if (element == null)
continue; // Should have been invalid but Serilog didn't check and so this does occur in the wild.
// Null elements should have been invalid but Serilog didn't check, and so this does occur in the wild.
var element = sequence.Elements[i] ?? new ScalarValue(null);

if (first)
first = false;
else
if (i != 0)
{
_delimiter?.Evaluate(ctx, output);
}

var local = _keyOrElementName != null
? new(ctx.LogEvent, Locals.Set(ctx.Locals, _keyOrElementName, element))
? new EvaluationContext(ctx.LogEvent, Locals.Set(ctx.Locals, _keyOrElementName, element))
: ctx;

local = _valueOrIndexName != null
? new EvaluationContext(local.LogEvent, Locals.Set(local.Locals, _valueOrIndexName, new ScalarValue(i)))
: local;

_body.Evaluate(local, output);
}

Expand All @@ -101,8 +104,8 @@ public override void Evaluate(EvaluationContext ctx, TextWriter output)
? new(ctx.LogEvent, Locals.Set(ctx.Locals, _keyOrElementName, new ScalarValue(member.Name)))
: ctx;

local = _valueName != null
? new(local.LogEvent, Locals.Set(local.Locals, _valueName, member.Value))
local = _valueOrIndexName != null
? new(local.LogEvent, Locals.Set(local.Locals, _valueOrIndexName, member.Value))
: local;

_body.Evaluate(local, output);
Expand All @@ -129,8 +132,8 @@ public override void Evaluate(EvaluationContext ctx, TextWriter output)
? new(ctx.LogEvent, Locals.Set(ctx.Locals, _keyOrElementName, element.Key))
: ctx;

local = _valueName != null
? new(local.LogEvent, Locals.Set(local.Locals, _valueName, element.Value))
local = _valueOrIndexName != null
? new(local.LogEvent, Locals.Set(local.Locals, _valueOrIndexName, element.Value))
: local;

_body.Evaluate(local, output);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ Template Transform(Repetition rep, Stack<string> locals)
locals.Pop();

return new Repetition(
rep.Enumerable,
ExpressionLocalNameBinder.BindLocalValueNames(rep.Enumerable, locals),
rep.BindingNames,
body,
rep.Delimiter != null ? Transform(rep.Delimiter, locals) : null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ A{#if false}B{#else if false}C{#else if true}D{#else}E{#end} ⇶ AD
A{#if false}B{#else if true}C{#end} ⇶ AC
{#if true}A{#if false}B{#else}C{#end}D{#end} ⇶ ACD
{#each a in [1,2,3]}<{a}>{#delimit},{#end} ⇶ <1>,<2>,<3>
{#each a, i in [1,2,3]}<{a}>({i}){#delimit},{#end} ⇶ <1>(0),<2>(1),<3>(2)
{#each a in {x: 1, y: 2}}{a}{#end} ⇶ xy
{#each a, b in {x: 1, y: 2}}{a}.{b}{#end} ⇶ x.1y.2
{#each a, b in {x: {y: 'z'}}}{#each c, d in b}A: {a}, C: {c}, D: {d}{#end}{#end} ⇶ A: x, C: y, D: z
{#if true}A{#each a in [1]}B{a}{#end}C{#end}D ⇶ AB1CD
{#each a in []}{a}!{#else}none{#end} ⇶ none
Culture-specific {42.34} ⇶ Culture-specific 42,34
Expand Down